Search code examples
labelprometheusgrafanametrics

Use label as metric in Grafana Prometheus source


Hello everyone I have prometheus as a label returns the amount. The metric value is the number of payments. How do I withdraw the total amount a day to the dashboard? i.e. value_metric*sum enter image description here


Solution

  • As far as I know, there is no way to do that because labels aren't meant to be used in calculations. Labels and their values are essentially the index of Prometheus' NoSQL TSDB, they're used to create relations and join pieces of data together. You wouldn't store values and do math with column names of a relational database, would you?

    Another problem is that labels with high cardinality greatly increase database size. Here is an extraction from Prometheus best practices:

    CAUTION: Remember that every unique combination of key-value label pairs represents a new time series, which can dramatically increase the amount of data stored. Do not use labels to store dimensions with high cardinality (many different label values), such as user IDs, email addresses, or other unbounded sets of values.

    Though I see that you use somewhat fixed values in labels, maybe a histogram would fit your needs.