英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论