I'm collecting cpu usage measured in jiffies by Collectd 5.4.0 and then storing the results in InfluxDB 0.9.4. I use the following query to get cpu percentage from InfluxDB:
SELECT MEAN(value) FROM cpu_value WHERE time >= '' and time <= '' GROUP BY type,type_instance
But when I plot the result it makes no sense. There is no pattern in cpu usage. Please let me know If I do something wrong.
Thanks
Since Collectd 5.5 you can get values in percentage instead of jiffies:
<Plugin cpu>
ReportByState = true
ReportByCpu = true
ValuesPercentage = true
</Plugin>
Then you can write query like:
SELECT mean("value") FROM "cpu_value" WHERE
"type_instance" =~ /user|system|nice|irq/
AND "type" = 'percent' AND $timeFilter
GROUP BY time($interval), "host"
If you can upgrade it might be the easiest option. Otherwise you can:
With InfluxDB 0.12 you can perform arithmetic operations between fields like:
SELECT MEAN(usage_system) + MEAN(usage_user) AS cpu_total
FROM cpu
However for using this you would have to report from collectd user|system|nice|irq
as FIELDS
not TAGS
.
this is my query, I use it with percent unit (on Axes tab), but stack+percent (on display tab) make sense as well
SELECT non_negative_derivative(mean("value"), 1s) FROM "cpu_value" WHERE "type_instance" =~ /(idle|system|user|wait)/ AND $timeFilter GROUP BY time($interval), "type_instance" fill(null)
The non_nagative_derivative(1s) can be replaced with derivative(1s), I had some of negative value when values was missing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With