Cpu usage per Node

253 views
Skip to first unread message

ah...@reezocar.com

unread,
Mar 22, 2019, 5:46:33 AM3/22/19
to Prometheus Users
Hello guys !

am trying to collect informations about the cpu usage per node i wrote this query sort(rate(node_cpu_seconds_total{mode="user"}[5m]) * 100 !=0)
but this query returns values for every cpu core per node . what i have to do to sum the values for every core in node cpu and devide it  on the number of cores and display the result for every node

bakou....@gmail.com

unread,
Mar 22, 2019, 6:52:02 AM3/22/19
to Prometheus Users
sort(sum(rate(node_cpu_seconds_total{mode="user"}[5m]) * 100)by("the variable of the node"))

Ben Kochie

unread,
Mar 22, 2019, 8:46:07 AM3/22/19
to bakou....@gmail.com, Prometheus Users
Better, is to use `without (mode,cpu)`, allows all other labels to be passed through.

sum without (mode,cpu) (
  rate(node_cpu_seconds_total{mode!="idle"}[5m])
)

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/3d216952-a916-428b-8ff2-8fc61b1efc72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Siebenmann

unread,
Mar 22, 2019, 11:14:28 AM3/22/19
to ah...@reezocar.com, Prometheus Users, cks.prom...@cs.toronto.edu
> am trying to collect informations about the cpu usage per node i wrote
> this query *sort(rate(node_cpu_seconds_total{mode="user"}[5m]) * 100
> !=0)* but this query returns values for every cpu core per node . what
> i have to do to sum the values for every core in node cpu and devide
> it on the number of cores and display the result for every node

The simple and faster way to do this is to use avg(), instead of trying
to count how many CPUs your machine has in order to divide the sum() by
it. So:

(avg( rate(node_cpu_seconds_total{mode="user"}[5m]) ) without (cpu)) * 100

(Using avg() instead of sum() divided by CPU count is not original
to me. I got the idea from a commentator on my blog, who pointed out
the equivalence.)

- cks

Ben Kochie

unread,
Mar 23, 2019, 6:52:14 AM3/23/19
to Chris Siebenmann, ah...@reezocar.com, Prometheus Users
Yup, this is a very good way to do it.

Another way to express the "whole CPU use" would be like this:

avg without (cpu) (
  sum without (mode) (
    rate(node_cpu_seconds_total{mode!="idle"}[5m])
  )
)

Maybe I should add this as a canonical example to the example rules[0].


--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages