How to calculate this avg_over_time ?

12,799 views
Skip to first unread message

petar...@mint.rs

unread,
Jul 19, 2018, 10:16:06 AM7/19/18
to Prometheus Users
Hi,
I need one help. I suggest this is simple for someone much exprienced than me in Prometheus.

I have this metric for CPU:

system_cpu_percentage_average{chart="system.cpu",family="cpu",dimension="user",host="example.com"}
system_cpu_percentage_average{chart="system.cpu",family="cpu",dimension="system",host="example.com"}
system_cpu_percentage_average{chart="system.cpu",family="cpu",dimension="softirq",host="example.com"}
system_cpu_percentage_average{chart="system.cpu",family="cpu",dimension="irq",host="example.com"}
system_cpu_percentage_average{chart="system.cpu",family="cpu",dimension="guest",host="example.com"}
system_cpu_percentage_average{chart="system.cpu",family="cpu",dimension="iowait",host="example.com"}
system_cpu_percentage_average{chart="system.cpu",family="cpu",dimension="nice",host="example.com"}
system_cpu_percentage_average{chart="system.cpu",family="cpu",dimension="idle",host="example.com"}
system_cpu_percentage_average{chart="system.cpu",family="cpu",dimension="steel",host="example.com"}


I need average (avg_over_time, 10 minutes) of the sum of dimensions user,system,softirq,irq,guest which is bolded above.
I tried everything and I can't make calculation.
Please, how to do this, thank you.

Julius Volz

unread,
Jul 19, 2018, 5:39:26 PM7/19/18
to Petar Kozić, Prometheus Users
Would the following be what you are looking for?

  avg_over_time(system_cpu_percentage_average{dimension=~"user|system|softirq|irq|guest"}[10m])

But the metric name ("xxx_average") suggests you are already dealing with an average. It doesn't say over what time it averages though...

--
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-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/2b166ea2-67b9-47c5-85b8-8cc79d1fef9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Petar Kozić

unread,
Jul 20, 2018, 5:22:52 AM7/20/18
to Julius Volz, Prometheus Users
But the metric name ("xxx_average") suggests you are already dealing with an average. It doesn't say over what time it averages though...

Yes I know that, forget that.

But I need average of sum all this dimenisons:

dimension=“user"

dimension=“system"

dimension=“softirq"

dimension=“irq”

dimension=“guest"


I don’t know how to do that, if I try this:

avg_over_time(sum(netdata_system_cpu_percentage_average{chart="system.cpu",family="cpu",dimension=~"user|system|softirq|irq|guest",host="node1.cloud.mint-cloud.com"}))[10m]

this don’t work.

Please advice ! Thanks.



Julius Volz

unread,
Jul 20, 2018, 6:31:24 AM7/20/18
to Petar Kozić, Prometheus Users
Ah, I see. Yeah, that's unfortunately not possible, as you can only select range vectors ("foo[10m]") on raw underlying data, not on arbitrary subqueries.


You would have to record the sum using a recording rule first, then max_over_time() over the recorded metric.

However: in your case where underlying averages represent equal time ranges, could you average over time first and then sum and get the same result?

sum(avg_over_time(foo[10m]))

Reply all
Reply to author
Forward
0 new messages