Reputation: 99
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?
Upvotes: 1
Views: 2759
Reputation: 135
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.
Upvotes: 0
Reputation: 9
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)
Upvotes: 0