1

I'm using the new InfluxDB2 and the flux query language to retrieve docker stats from my bucket. I want to display the uptime of a container in a single stat widget.

For this I use the following query:

   from(bucket: "docker")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "docker_container_status")
  |> filter(fn: (r) => r._field == "uptime_ns")
  |> filter(fn: (r) => r.container_name == "some_container")
  |> window(period: v.windowPeriod)
  |> last()

Unfortunately, the container wasn't online in the past time range, therefore I get a "No results" displayed. Instead I would like to display a 0 value or a text like "Not online".

How can I achieve this?

Progman
  • 16,827
  • 6
  • 33
  • 48
totkeks
  • 89
  • 2
  • 9

2 Answers2

0

Try this query, when there is no data, it should use 0.0 to fill

   from(bucket: "docker")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "docker_container_status")
  |> filter(fn: (r) => r._field == "uptime_ns")
  |> filter(fn: (r) => r.container_name == "some_container")
  |> aggregateWindow(every: v.windowPeriod, fn: (tables=<-, column="_value") => 
tables |> last(column) |> sum(column))
  |> fill(value: 0.0)
Z ketchup
  • 9
  • 2
0

If you are using Grafana you can use the option for "No value" to select what you want displayed if there are no results / No Data from your query.

Spider999
  • 135
  • 1
  • 8
  • 17