Quantcast
Channel: InfluxDB - Grafana Labs Community Forums
Viewing all articles
Browse latest Browse all 199

Calculating number of received and missing data points for time interval

$
0
0
  • What Grafana version and what operating system are you using?
    Grafana cloud (steady) (This is what appears when I hover over the “?” icon)
    MacOS Sonoma 14.5

  • What are you trying to achieve?
    Calculate and make a histogram and table of %data received. Our devices sometimes go offline and I want to know how much they are online.

  • How are you trying to achieve it?
    Using flux “exists”

  • What happened?
    My count_nan isn’t returning the number of data points that don’t exist but my count_exists is working. If I divide count_exists by the number of points I expect, it correctly give me a percentage. But count_nan is 0.

  • What did you expect to happen?
    I expect count_nan to equal missed points.

  • Can you copy/paste the configuration(s) that you are having problems with?

    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r._field == “temp”) //

    // Calculate counts of non-NaN and NaN values
    |> reduce(
    identity: {count_exists: 0, count_nan: 0}, // Initialize as integers
    fn: (r, accumulator) => ({
    count_exists: if exists r._value then accumulator.count_exists + 1 else accumulator.count_exists,
    count_nan: if exists r._value then accumulator.count_nan else accumulator.count_nan + 1 // Increment count_nan if _value is missing
    })
    )

    // Calculate uptime percentage and add device_id as _time
    |> map(fn: (r) => ({
    r with
    test: float(v: r.count_exists)/ (float(v: r.count_exists)+float(v: r.count_nan)),
    _time: r.device_id // Replace _time with device_id for display
    }))
    |> keep(columns: [“_time”, “_field”, “_value”, “test”]

// Pivot data using uptime as value
|> pivot(rowKey: [“_time”], columnKey: [“_field”], valueColumn: “test”)
|> rename(columns: {_time: “device_id”, temp: “uptime”})
|> yield(name: “uptime”)

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    There are no errors for this. Just no data shows.

  • Did you follow any online instructions? If so, what is the URL?
    I’ve just been using the flux documentation.

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 199

Trending Articles