Search code examples
grafanainfluxdbtelegrafinfluxql

How to write case when query in influxdb?


I have a Grafana + InfluxDB + Telegraf setup to monitor my organization's servers. I want to make a dashboard in which I will be monitoring computer resources such as CPU , RAM etc of multiple servers. I want to show just '0', If my server processor is above 80% and '1', if server processor is below 80% in Grafana dashboard. For this how can I use CASE WHEN statement to show 0/1 depending upon the threshold that I set.


Solution

  • CASE WHEN doesn't exist in InfluxDB. You have to use math in your InfluxDB query to map value range 1-80-100 into new value range 1-0. Idea:

    FLOOR(1/(your_cpu_field/80))
    

    Doc: https://docs.influxdata.com/influxdb/v1.6/query_language/functions/