【问题标题】:Compare 2 metrics in Prometheus比较 Prometheus 中的 2 个指标
【发布时间】:2018-05-10 14:18:14
【问题描述】:

我是 prometheus 的新手,需要帮助。

我的 2 台服务器上有自定义指标(仅显示应用程序的版本):

app_version{plant="dev",env="demo"} 55.119
app_version{plant="dev",env="live"} 55.211

我想比较这些指标,如果它们不相等,我想发送警报:

alert: Compare
expr: app_version{env="demo"} != app_version{env="live"}
for: 5s
labels:
  severity: page
annotations:
  summary: Compare

这个警报是绿色的。 比较 2 个指标的正确方法是什么?

【问题讨论】:

    标签: compare monitoring metrics prometheus


    【解决方案1】:

    env 标签的不同值意味着表达式的每一侧都没有可匹配的内容,因此它不返回任何内容,也没有警报。您可以使用ignoring 调整此行为:

    app_version{env="demo"} != ignoring (env) app_version{env="live"}
    

    【讨论】:

    • 如果我们需要忽略一些标签我们应该使用逗号(忽略(label1,label2))还是少数忽略运算符?
    • 从 Prometheus GUI 添加图片
    • app_version{env="demo"} != ignoring(env, instance) app_version{env="live"} 也不起作用
    • 我想通了。只是忘记了其他具有不同值的标签(如“服务”)。最终表达式如下: expr: app_version{env="demo"} != ignoring(env, instance, service) app_version{env="live"}
    猜你喜欢
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多