Aggregate same metric, different labels at scrape time

Viewed 488

Given a metrics with various labels (i.e., same metric name with different labels), is it possible to aggregate these at scrape time into a single value, e.g., by summing all the values?

I know this is possible at query time, but I'm asking about scrap time as idea is to reduce the number/cardinality of metrics stored in prometheus.

For example, given the following metric output:

some_metric{server="server-0"} 30  1395066363000
some_metric{server="server-0"} 70  1395066363000
some_metric{server="server-0"} 100 1395066363000

I'd like to drop the server label and import it as if it was:

some_metric 200 1395066363000
1 Answers

I think you can use relabel_configs or metrics_relabel_configs and labeldrop.

Be careful that you don't cause a collision in your resulting metrics though (two metrics previously differing by their labelsets could collide).

There's an explanation of the difference between them here

Related