使用 Prometheus 警报管理器使用多个指标发送警报

Sending alert using multiple metric with Prometheus alert manager

我正在针对某个业务案例评估 Prometheus。我一直在关注文档,但找不到描述我的要求的示例。

下面是我的商业案例。

我将在一个 PULL 周期中使用以下指标将数据 (PULL) 泵送到 Prometheus。当然,在一个 PULL 周期中,我也可以抽取另一组完全相同的指标,但资产 ID 会有所不同。

test_value_one{asset_id="123"} 0.215
test_value_two{asset_id="123"} 0.815
test_value_six{asset_id="123"} 0.715

我的问题是

我可以使用多个指标(相同的资产 ID)构建单个规则吗?我认为可以将多个指标与表达式 (expr) 一起使用。但我的要求如下。

name: iot_rules
  rules:
  - alert: threshhold_alert
    expr: test_value >= 4
    #for: 1m
    labels:
      severity: critical     
      Additional text : The other metric values are 0.815 and 0.715
    annotations:      
      summary: 'Error detected on {{$labels.assset_id}}'

如果您查看警报规则中的附加文本,值 0.8150.715 需要来自其他两个指标即分别为 test_value_twotest_value_six。这是我可以实现的吗,因为我的目标是在我打算发送的单个警报中提供其他指标的全面视图。

你可以试试

expr: test_value_one - test_value_two >= 4  or test_value_two - test_value_six >= 4

或类似

我的 alert-manager.yml 上的以下配置有助于根据 asset-id 聚合数据。请注意下面的 "group_by" 标记。我从构建所需文本的地方公开了 promwebhook 的 RESTAPI。

global:

route:
  group_by: ['asset_id']
  group_wait: 5s
  group_interval: 5s
  repeat_interval: 2m
  receiver: node