Prometheus 获取直方图计数占总数的百分比
Prometheus get histogram counts as percentages of total
我在 Prometheus 中有一个直方图,而在 Grafana 中,我试图获取其中一个标签的计数分布图,以百分比表示。我目前正在尝试
sum(rate(histogram_count{label1="value1"}[5m])) by (label2)
/
sum(rate(histogram_count{label1="value1"}[5m]))
但它没有返回任何值。难道我做错了什么?我只想要 label2 的每个值的计数总和除以计数总和。
问题是两边的标签不匹配。您可以使用 group_left
进行多对一匹配,并使用 ignoring
忽略不匹配的标签:
sum by (label2)(rate(histogram_count{label1="value1"}[5m]))
/ ignoring (label2) group_left
sum(rate(histogram_count{label1="value1"}[5m]))
有关详细信息,请参阅 https://www.robustperception.io/using-group_left-to-calculate-label-proportions
我在 Prometheus 中有一个直方图,而在 Grafana 中,我试图获取其中一个标签的计数分布图,以百分比表示。我目前正在尝试
sum(rate(histogram_count{label1="value1"}[5m])) by (label2)
/
sum(rate(histogram_count{label1="value1"}[5m]))
但它没有返回任何值。难道我做错了什么?我只想要 label2 的每个值的计数总和除以计数总和。
问题是两边的标签不匹配。您可以使用 group_left
进行多对一匹配,并使用 ignoring
忽略不匹配的标签:
sum by (label2)(rate(histogram_count{label1="value1"}[5m]))
/ ignoring (label2) group_left
sum(rate(histogram_count{label1="value1"}[5m]))
有关详细信息,请参阅 https://www.robustperception.io/using-group_left-to-calculate-label-proportions