5
votes

I'm using Telegraf/InfluxDB/Grafana to register and view metrics for my servers. Occasionally one of these components crash and metrics stop flowing into InfluxDB.

To be able to notice when this happens (on top of using Monit to restart the service) I would like to create a Grafana dashboard where I have a singlestat panel for each host that shows the most recent timestamp (or better, how much time has passed) since the last metric was received. I'd also like to colorize the background of the singlestat depending on how long it's been. I would like to be able to do this for any InfluxDB metric, as different metrics can have different reasons for lagging behind.

Right now, I've tried something like this in InfluxQL, but I just get an error that at least one non-time field must be present in the query:

SELECT last(time) FROM "system" WHERE "load1" > -1 GROUP BY "host"

If I try to change it to this I get a "Multiple series error":

SELECT last(time), last("load1") FROM "system" GROUP BY "host"

Is what I'm trying to do not easily doable or am I missing something obvious?

1
An almost similar question is asked here: stackoverflow.com/questions/35640978/…Robin Smidsrød
This would be a really nice feature but it is not possible at the moment.IIIIIIIIIIIIIIIIIIIIII
Your question is also a duplicate of: stackoverflow.com/q/39534892/5183341IIIIIIIIIIIIIIIIIIIIII
This might be a viable answer: stackoverflow.com/a/49321045/132317Robin Smidsrød

1 Answers

0
votes

Influxdb query to get most recent timestamp

...the query syntax was taken from somewhere in this issue. I haven't yet looked at the singlestat panel, but I suggest creating a 'scripted dashboard'.
Start by manually creating a singlestat dash with a dummy number. Then export it to see what the json looks like. Then, recreate that same json, with the live result from the above query, using a scripted dashboard.

Look in grafana's /public/dashboards for 'scripted.js' or 'scripted_templated.js'. Make a copy of one of those in the same folder, then hack away to generate your json. Here and here and here are some nice examples for the javascript magic to submit the query to influxdb and parse the result into the json for your singlestat dash. Good luck.