'Find exact CPU percentage from the metrics exported by prometheus-node-exporter

I use the node_cpu_seconds_total metrics for this.

Basically, I want to subtract mode="idle" from the total CPU usage and then take the avg rate of the result, then a percentage calculation.

I tried something like:

100 - (avg(rate(node_cpu_seconds_total{instance="ip-X-X-X-X.eu-west-1.compute.internal:9100",job="rabbitmq-prod-node-exporter",replica="prometheus-prod"} - node_cpu_seconds_total{instance="ip-X-X-X-X.eu-west-1.compute.internal:9100",mode="idle",job="rabbitmq-prod-node-exporter",replica="prometheus-aws-prod"}))[1m] * 100)

But does not seem to be proper and also shows a parse error:

Error executing query: parse error at char 177: range specification must be preceded by a metric selector, but follows a *promql.AggregateExpr instead


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source