Search code examples
influxdbgrafanaproxmox

Jiffies to percentage in InfluxDB


I am collecting data from a Proxmox host into an InfluxDB datasource. This datasource is used to power a Grafana dashboard. Data is collected as it should, but I have a problem plotting the CPU usage.

I have figured out that the data that is sent concerning the CPU is sent as jiffies, so I figured that;

System / System + User + Idle = Percentage System CPU Usage

I then have to take a mean of all those values to get the mean System CPU usage for the last minute. Here is where i run into a problem. The InfluxDB documentation states

The use of mathematical operators inside of function calls is currently unsupported.

as can be found here InfluxDB documentation

My question is if there is a workaround for this so I can calculate the mean of a sum.


Solution

  • There is a way to do this with InfluxDB, but its a two step process.

      SELECT System / (System + User + Idle) AS avg
      INTO "sys_cpu" FROM "my_measurement"
    

    Then simply issue a query

    SELECT mean(value) FROM "sys_cpu" GROUP BY time(<interval>)
    

    Its kind of messy, but should work.