Prometheus - Convert cpu_user_seconds to CPU Usage

2019-03-19 09:29发布

问题:

Currently i'm monitoring docker containers via Prometheus.io. My problem is that i'm just getting "cpu_user_seconds_total" or "cpu_system_seconds_total". My question is how to convert this ever-increasing value to a CPU percentage?

Currently i'm querying:

rate(container_cpu_user_seconds_total[30s])

But I don't think that it is quite correct (comparing to top).

How to convert cpu_user_seconds_total to CPU percentage? (Like in top)

回答1:

Rate returns a per second value, so multiplying by 100 will give a percentage:

rate(container_cpu_user_seconds_total[30s]) * 100



回答2:

I also found this way to get CPU Usage to be accurate:

100 - (avg by (instance) (irate(node_cpu_seconds_total{job="node",mode="idle"}[5m])) * 100)

From: http://www.robustperception.io/understanding-machine-cpu-usage/