Influxdb Data availability dashboard

Greetings

I am visualizing the real time data from influxdb in grafana dashboards. In my influxdb thereis a measurement and it has around 10 tags which has data (fields) from 10 different sources(users). In this measurement data are coming in every 5 mins. But sometimes some tags or datasource has no data coming for like hour or day. So, I am working on a dashboard which shows how much data is available in that tag in certain time period. Suppose i select 1 week time range so the tag should have 10,800 data points for one field, i want to calculate percentage with given datapoints with respect to total data points it should have if data is coming in every 5 mins in influx data. I am using flux query. How can i calcluate this using flux query in the dashboard for a given time frame so that % also changes for selected time frame ?

Thank you much

Hi @leonardoselex

I currently have no access to a computer to test this, but off the top of my head…

  1. assume you have a start time and end time for the desired time frame.
  2. as data points come in every 5 minutes, you can divide the total duration in minutes by 5. For example, if the time range is one week (7 days), the total number of data points would be (7 * 24 * 60) / 5 = 2016 data points. However, to do the above, you need to calculate the duration between the stop time from the start time. Flux doesn’t support mathematical operations using time type values. To calculate the duration between two timestamps, follow these instructions.
  3. Use Flux query to retrieve the actual count of data points available for the specific tag within the given time range. You can use the range() function to specify the time range and the count() function to count the data points:
data = from(bucket: "your-bucket")
  |> range(start: your-start-time, stop: your-end-time)
  |> filter(fn: (r) => r._measurement == "your-measurement" and r._field == "your-field" and r.your-tag == "your-tag-value")
count = data |> count()

  1. Calculate the percentage by dividing the actual count of data points by the total count of data points and multiplying by 100.