Many to One

Sometimes you want to do a Many to One match.

In the last page we calculated idle CPU as a ratio of total. What if we wanted to do that for all CPU modes?


We would use the group_left modifier. Many is the left side. We keep all the labels on the many side, and copy over any labels listed in the group_left.



This gives us the expression:

  sum without (cpu)(rate(node_cpu[5m])) 
/ ignoring(mode) group_left 
  sum without (mode, cpu)(rate(node_cpu[5m]))

The bucketing will look like:

LHS

RHS

{mode=”idle”,instance=”machine1″,job=”node”}

{instance=”machine1″,job=”node”}

{mode=”user”,instance=”machine1″,job=”node”}

{mode=”system”,instance=”machine1″,job=”node”}


And the in the expression browser would look like:


group_right is similar, switching LHS and RHS. You are unlikely to have a need for it.