Trevor Jordy
Trevor Jordy

Reputation: 658

Grouping metrics with the same value to a label without knowing the label values with PromQL

My situation is this: I am using Prometheus with Grafana, and with a graph, want to sum() my metrics in groups based on what their value of the label "mylabel" is. I have a metric, mymetric, with label mylabel.

mymetric{name: thing1, mylabel: a}
mymetric{name: thing2, mylabel: b}
mymetric{name: thing3, mylabel: a}

I want all of my metrics with mylabel value "a" to be sum() together into one line on the graph, while metrics with mylabel value "b" are sum() together onto the same graph. The problem is, I don't know what values "a" and "b" will be. I just want things that happen to have the same value to be sum together.

Is this possible?

Upvotes: 6

Views: 10690

Answers (1)

brian-brazil
brian-brazil

Reputation: 34122

In general you don't need to know the label values for aggregation, so:

sum by (mylabel)(mymetric)

Upvotes: 8

Related Questions