Hi, I’m new in PromQL
- I have lots of VMs, almost 300. each VM has prometheus label named “team”
- (1) I add each team’s VMs cpu usage(team A, team B, team C, …)
- (2) I add all VM’s cpu usage(team A+team B+team C+team D+…)
- (3) so I want (1) / (2) * 100, so that make “team’s CPU usage(%) in all servers”
PromQL Query that i tested below :
(1) each team’s VMs avg
avg by(team) ((100 - sort(avg by (instance,team (irate(node_cpu_seconds_total{team=“A”,mode=“idle”}[3m])) * 100)))
(2) all VMs avg
sum ((100 - sort(avg by (instance,team) (irate(node_cpu_seconds_total{team!=“”,mode=“idle”}[3m])) * 100)))
(3)
avg((100 - sort(avg by (instance,team) (irate(node_cpu_seconds_total{team=“A”,mode=“idle”}[3m])) * 100))) / (sum ((100 - sort(avg by (instance,team) (irate(node_cpu_seconds_total{team!=“”,mode=“idle”}[3m])) * 100)))) * 100
but, as you know,
(2) has just value, no label… so i can’t calculate (1) / (2) because of label match problem
if i use “avg” instance of “avg by (team)” in front of (1), it’ll calculated (3),
but that result has no label, so I can’t use it another tool(like Grafana)
So… The Question is:
How can i Add label when just use “sum”, not “sum by” in PromQL Query Result.
Thank You