PromQL: operations with expressions

154 views
Skip to first unread message

Maxim Filatov

unread,
Sep 23, 2016, 2:59:36 PM9/23/16
to Prometheus Developers
Hello!

I have Prometheus + Telegraf + Grafana and want to get “CPU usage” on SingleStat.

CPU usage: sum(cpu_usage_idle{host=~".*", cpu="cpu-total”})

Num of hosts: count by (cpu)(cpu_usage_idle{host=~".*",cpu="cpu-total”})

The final expression: sum(cpu_usage_idle{host=~".*", cpu="cpu-total"})/count by (cpu)(cpu_usage_idle{host=~".*",cpu="cpu-total”})

This expression returns no data, but if I place integer after “/“, it works as expected.

What am I doing wrong?

Thanks in advance.

-- 
Best regards,
Maxim Filatov

Maxim Filatov

unread,
Sep 23, 2016, 3:01:35 PM9/23/16
to Prometheus Developers
Forget to add "100 - …”, but it no affects the result ;)

-- 
Best regards,
Maxim Filatov

Maxim Filatov

unread,
Sep 24, 2016, 5:35:46 AM9/24/16
to Prometheus Developers
Answering to myself.

In left part of equation I has {} - value, but in right there was {host} - value.
Additional “sum” saves the day.

Final “formula”:

100 - sum(cpu_usage_idle{host=~"$host.*", cpu="cpu-total"})/sum(count by (cpu)(cpu_usage_idle{host=~"$host.*",cpu="cpu-total"}))
Reply all
Reply to author
Forward
0 new messages