Not entirely sure if this is the right place to ask this question as I’m new to Grafana.
Here is my problem:
I’m ingesting data from my devices to the Influxdb back end. There are some cases where a sensor fails to send metrics to the database. I need to find a way to put all static list of devices as a “Single Stat” panel -side by side- into the dashboard I’m working on. When I filter last 3 hours from the dashboard time filter (top right) for example, naturally Grafana shows the devices only that sent metric within last 3 hours. I want to show them all, but colour the ones that didn’t sent anything for the given duration though.
Is that possible? How? I’d appreciate any advise on this.
Depending on the metrics you’re recording from these sensors, is there any
value which could be interpreted as “null”, “never mind”, “dummy” etc?
I have implemented something like the following for a similar situation (in my
case, monitoring the number of phone calls through a set of Asterisk PBXs,
where for some time periods there may not be any phone calls, but I still
want the PBX to be listed…):
Firstly, the real source of the data writes (via telegraf in my case) to
InfluxDB, to get the values I want to see into the data store.
Secondly, a separate process writes on a regular basis a dummy record into the
same data store, bearing the names of each of the real data sources. That
guarantees that for every “time interval” there is at least one record in the
data store bearing the name of a (PBX in my case; sensor in your case).
The choice of what “time interval” to choose depends purely on what the
shortest time interval might be that you ask Grafana to report on.
Then, so long as Grafana can ignore whatever data the “dummy values” contain
(in my case, zero works fine for “how many calls are in progress?”, but your
situation may be different), you know there will definitely be at least one
entry in the data store, and if there’s more than one, some of them will
contain reportable values.
Maybe that will at least give you some inspiration for a solution.
If you can write InfluxDB query for that, then Grafana is able to visualize it. So it isn’t really a problem of the Grafana, but it is InfluxDB issue. I’m using:
SELECT * FROM ( SELECT last(*) FROM "metrics" GROUP BY "device-tag" ) WHERE time<NOW()-$limit
$limit is my dashboard variable (e.g. 1h,1d,30d), so I can select missing period easily.
Yes, it is very inefficient query. Yes, it may kill your InfluxDB server eventually. Let us know if you are able to write better query for “detect missing metrics” task.
Figure out what’s the longest period of time a device can be in a “no data” state. Let’s say it’s 1 day. Create a query that covers twice that amount, or a few times more, so that all valid device ids will show up in the results:
SELECT last("some_field") FROM "some_sensor_measurement" WHERE time>now()-2d GROUP BY time(1m), device FILL(null)
The choice of
1m in the
GROUP BY means that it will take 1 minute for the device to show as offline.
In the visualization options, add a data mapping:
In the display options for the Stat panel, set
last or any choice that suits your needs.
In the threshold options, you want the base color as red and a threshold of
0 as green. Or whatever base value works for your data.
That’s an excellent answer and almost exactly what I’ve asked for.
However, one last thing is missing.
The panel query looks like this:
And panel visual is like this:
In the panel, the numbers in large letters are the last value of the file_size fields per device. If the file_size is not null, it shows the file size. However, I’d like to show the device number. Any ideas?