What timestamp values to use to plot cummulative period hour\day data

  • What Grafana version and what operating system are you using?
    Yet to install Grafana but will be running on Rasp Pi / Debian

  • What are you trying to achieve?
    I am writing a python program that outputs statistical data for various time periods:

  • data A for each device 1, 2, 3 for period 1 (e.g. 4 mins)

  • data A for each device 1, 2, 3 for period hour

  • data A for each device 1, 2, 3 for period day

  • data B for device 4 for period hour

  • data B for device 4 for period day
    All the data is cumulative values for the period

  • How are you trying to achieve it?
    The data is being sent as MQTT/json with different topics and it is intended to store it in an influxdb database before processing by grafana
    The data is timestamped, e.g. “dateTime”: “2021-09-20 23:52:38”

  • Issue
    The time periods are triggered by python timers and in the case of data B there are slight delays to ensure that the data A has been processed.

So for example the last hour’s data A on 2021-09-20 is timestamped “2021-09-21 00:00:00” (i.e. the next hour/day) and the data for B for the whole of the same day is “2021-09-21 00:05:00” (i.e.next day).

  • Question
    How should I timestamp cumulative data so that it is analysed and reported in grafana for actual hour/day that the data represents?

I would for example, expect a graph of data for each hour in a day to have the last hour labelled as 23 or 23:00-23:59

For instance, should I subtract x secs from the current time so that the timestamp is the end of the previous hour/day?

I’m sure that this is a issue that applies to all time series data but it’s years since I created any such data.
Thanks
Alan

@alanuk,

First, what datasource plugin are you using to pull your data into Grafana?

Second, based on your datasource, I would explore using the global time variables:

the Python client for Prometheus exporter?

Hi Matt. Thanks for the suggestion. I just looked at a YT vid of Influx vs Prometheus. Prometheus has some good features but given I’ve already built my data source app then I think Influx will be more suitable.

Thanks as well for your first post:

First, what datasource plugin are you using to pull your data into Grafana?

Well if I go for Influx then I read there is a native plugin for InfluxDB in Grafana

Second, based on your datasource, I would explore using the global time variables:

Yes, that looks suitable for the start and stop timestamps. I was then wondering how Grafana splits the data when graphing. What I’ve done is insure that all my timestamps are within the time period analysed by subtracting 10 seconds.

E.g. if I sample every 5 minutes from 1:00 to 2:00 (12 samples) then if the last sample is taken at say 2:00:05 (due to processor time lag) then I timestamp it at 1:59:55 so that the hour has the correct 12 samples.

Once I’ve installed Grafana I shall see with test data if this works correctly.

Alan

This topic was automatically closed after 365 days. New replies are no longer allowed.