PromQL:比较指标值与其标签的值

huangapple go评论68阅读模式
英文:

PromQL : compare metric value with its label's value

问题

我有这个度量标准:my_metric{expected_value="123"} 123

使用Prometheus,如何创建一个警报,当值与标签expected_value的值不同时触发?

英文:

I have this metric : my_metric{expected_value="123"} 123

Using Prometheus, how can create an alert that triggers when the value differs from the label expected_value's value ?

答案1

得分: 1

你不能这样做。标签不应该以这种方式使用,而且没有结合标签和度量值的方法。

在这种情况下,最佳做法是将您的度量值拆分为两个度量值:

my_metric 123
my_metric_expected_value 123

然后根据表达式引入告警规则:

my_metric != my_metric_expected_value
英文:

You cannot. Labels are not supposed to be used in this way, and there are no ways of combination labels and metric values.

Best course of action in this case would be to split your metric into two metrics:

my_metric 123
my_metric_expected_value 123

And introduce alerting rule based on expression:

my_metric != my_metric_expected_value

答案2

得分: 1

Prometheus不允许将标签值与度量值进行比较,如此答案所述。如果您仍然想要这样做,那么请尝试在我工作的类似Prometheus的替代系统中使用以下查询:

label_value(my_metric, "expected_value") != my_metric

它使用label_value函数从my_metric度量中的expected_value标签中提取数值标签值。

英文:

Prometheus doesn't allow comparing label value with metric value as said in this answer. If you still want to do this, then try the following query in Prometheus-like alternative system I work on:

label_value(my_metric, "expected_value") != my_metric

It uses label_value function for extracting numeric label value from the expected_value label at my_metric metric.

huangapple
  • 本文由 发表于 2023年6月29日 23:54:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76582720.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定