[英]Prometheus Query to aggregate metrics by certain label values
I have my metrics exposed by Prometheus as: Prometheus 将我的指标公开为:
custom_metric{label1="abc", label2="xyz"} num1
custom_metric{label1="def", label2="uvw"} num2
custom_metric{label1="ghi", label2="rst"} num3
custom_metric{label1="jkl", label2="opq"} num4
I want to query the metric such that I get sum of metric for label1="abc"
, label1="def"
and label1="jkl"
.我想查询指标,以便获得label1="abc"
、 label1="def"
和label1="jkl"
的指标总和。
I expect the result after querying to be something on lines of custom_metric_groupped (num1 + num2 + num4)
.我希望查询后的结果在custom_metric_groupped (num1 + num2 + num4)
行上。
Another thing, in my use case, the number of specific label values can vary.另一件事,在我的用例中,特定标签值的数量可能会有所不同。 So, it might be the case that in future I might want to only take the sum for label1="def"
and label1="jkl"
因此,将来我可能只想取label1="def"
和label1="jkl"
的总和
Try the following query:尝试以下查询:
sum(custom_metric{label1=~"abc|def|jkl"})
It works in the following way:它的工作方式如下:
custom_metric{label1=~"abc|def|jkl"}
- see these docs .它选择时间序列匹配标签选择器custom_metric{label1=~"abc|def|jkl"}
- 请参阅这些文档。 Note that the required values for the label1
are enumerated in the regexp filter with |
请注意, label1
所需的值在正则表达式过滤器中用|
枚举。 delimiter.分隔符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.