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_seconds_total[5m])) 
/ ignoring(mode) group_left 
  sum without (mode, cpu)(rate(node_cpu_seconds_total[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_left can also take a list of labels, which will copy the given label from the RHS to the LHS. This is mainly useful for what is known as the machine roles technique, which is covered in a later lesson.


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