Show Single Stat based on last value in specific column in dashboard

  • InfluxDB 2.0.7
  • Server: 2a45f0c
  • Frontend: 217d8c0

I am running a raspberry pi with a GPS HAT which provides me with accurate time. I would now like to monitor the statistics of this timeserver through a Dashboard. I am receiving data from the telegraf plugin which is installed on the raspberry pi, and I can with ease create dashboards in InfluxDB, graphically presenting the statistics from chronyc tracking.

This raspberry pi does have fallback NTP Servers, configured through chrony, in case the GPS does not receive signals, or whatever. As you can see on the raw data pasted below, it is reporting Stratum 1 - everything is OK and the GPS has good reception.

#datatype	string	long	dateTime:RFC3339	dateTime:RFC3339	dateTime:RFC3339	double	string	string	string	string	string	string
#default	_result											
	result	table	_start	_stop	_time	_value	_field	_measurement	host	leap_status	reference_id	stratum
		0	2022-05-26T12:35:40.631883888Z	2022-05-26T13:35:40.631883888Z	2022-05-26T12:39:10Z	0.000000046	system_time	chrony	ntp	normal	47505053	1
		0	2022-05-26T12:35:40.631883888Z	2022-05-26T13:35:40.631883888Z	2022-05-26T12:39:20Z	0.000000046	system_time	chrony	ntp	normal	47505053	1

What I want to do, is to create a Cell in my Dashboard which displays the last value in the column stratum. By achieving this, I can through a quick glance on the dashboard tell if the GPS HAT is working allright (if it is not 1 anymore, e.g. 2 or 3-- the GPS HAT has lost the signal).

But I do not understand how I can get that specific value in a “Single stat” cell! Can someone help me?


Hi - I gave this a try using the example data you posted. Mapping the stratum tag and value to _field and _value would give you the result you’re looking for. Not sure how often you need to check or how old the data can get, so may need to play around with the aggregateWindow

from(bucket: "unit-test")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "chrony")
  |> filter(fn: (r) => r["_field"] == "system_time")
  |> aggregateWindow(every: 24h, fn: last, createEmpty: false)
  |> map(fn: (r) => ({ _value: r.stratum, _field: "stratum", _time: r._time }))
  |> yield(name: "last")

Single Cell and Table showing the result of above flux

1 Like

Excellent, thank you very much :smile:

1 Like