'Prometheus show top metrics filtered by number of labels
According to this: https://prometheus.io/docs/practices/instrumentation/#do-not-overuse-labels i should stick to no more than 10 labels per metric.
I'm trying to write query which shows me top 10 metrics filtered by the number of labels they have. Is it possible?
Solution 1:[1]
Prometheus provides /api/v1/status/tsdb endpoint, which exposes metric names with the highest number of labels inside seriesCountByMetricName stats. It also exposes other useful stats, which may help determining the source of high cardinality:
- labels with the highest number of unique values at
labelValueCountByLabelNamestats label=valuepairs with the highest number of unique time series atseriesCountByLabelPairstats
P.S. Other Prometheus-like systems may provide additional functionality for /api/v1/status/tsdb endpoint, which can help narrowing down the source of high cardinality. For example, VictoriaMetrics provides the following additional functionality:
- Ability to specify the date for the stats via
datequery arg. For example,/api/v1/status/tsdb?date=2022-04-01would return stats for April 1, 2022. - Ability to specify the number of entries to return per each collected stats via
topNquery arg. For example,/api/v1/status/tsdb?topN=100would return up to 100 entries per eachstatslist. - Ability to filter out time series for stats collection via arbitrary time series selector. For example,
/api/v1/status/tsdb?match[]=foobarwould return stats for time series withfoobarname only.
See these docs for more info.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | valyala |
