【问题标题】:How to correctly configure Alerting yaml rules for Prometheus / Alertmanager如何正确配置 Prometheus / Alertmanager 的 Alerting yaml 规则
【发布时间】:2021-01-16 20:21:14
【问题描述】:

因为我在为 Prometheus Alertmanager 配置警报规则时遇到了可怕的事情,也许有人可以给我一个正确方向的提示。

以下是我目前正在尝试实施的规则(直接来自: https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/)

rules.yml:

groups:
- name: example
  rules:

  # Alert for any instance that is unreachable for >5 minutes.
  - alert: InstanceDown
    expr: up == 0
    for: 5m
    labels:
      severity: page
    annotations:
      summary: "Instance {{ $labels.instance }} down"
      description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."

  # Alert for any instance that has a median request latency >1s.
  - alert: APIHighRequestLatency
    expr: api_http_request_latencies_second{quantile="0.5"} > 1
    for: 10m
    annotations:
      summary: "High request latency on {{ $labels.instance }}"
      description: "{{ $labels.instance }} has a median request latency above 1s (current value: {{ $value }}s)"

使用 amtool 和 promtool 配置检查我收到以下错误:

Checking '/etc/prometheus/rules.yml'  FAILED: yaml: unmarshal errors:
  line 1: field groups not found in type config.plain

amtool: error: failed to validate 1 file(s)

我的第一个猜测是缩进错误或其他类型的 yaml 语法错误。 但是,我尝试了多个警报规则以及不同的文件以及编辑器(目前我正在使用 nano)。yaml 也已使用多个 yaml Linters 检查。 但就目前而言,我在显示的那一行中总是有错误。

任何帮助或建议将不胜感激!

prometheus, version 2.22.2 (branch: HEAD, revision: de1c1243f4dd66fbac3e8213e9a7bd8dbc9f38b2)
  go version:       go1.15.5
  platform:         linux/amd64
alertmanager, version 0.21.0 (branch: HEAD, revision: 4c6c03ebfe21009c546e4d1e9b92c371d67c021d)
  go version:       go1.14.4

yaml 短绒:

https://codebeautify.org/yaml-validator

https://onlineyamltools.com/validate-yaml

经过测试的警报规则:

https://onlineyamltools.com/validate-yaml

https://grafana.com/blog/2020/02/25/step-by-step-guide-to-setting-up-prometheus-alertmanager-with-slack-pagerduty-and-gmail/

https://rakeshjain-devops.medium.com/prometheus-alerting-most-common-alert-rules-e9e219d4e949

https://github.com/vegasbrianc/prometheus/blob/master/prometheus/alert.rules

【问题讨论】:

    标签: yaml prometheus prometheus-alertmanager


    【解决方案1】:

    groups 的解组失败,因为它应该是一个列表:

    groups:
    - name: GroupName
      rules:
      - alert: ...
    

    查看documentation about recording rules,与告警规则相同。


    帖子更正后更新

    您的文件似乎是正确的。命令行是:

    promtool check rules /etc/prometheus/rules.yml
    

    我希望您使用该命令来检查 config 而不是 rules

    请注意,amtool 验证 AlertManager 的配置,而不是 Prometheus 的配置。

    【讨论】:

    • 感谢您的评论,看来我发布了错误的 rule.yml(尝试了多个)。该帖子现在已编辑并包含我当前正在检查的 rule.yml。它只是从警报规则文档中复制和粘贴,但我仍然遇到同样的错误:/
    • 非常感谢,你让我开心!错误确实是检查规则!仍然让我感到困惑的是,我尝试加载给定的 rules.yml 而不首先使用 promtool 检查它(但仍然是完全相同的文件)并且 Prometheus 服务无法正确加载文件?
    • 如果没有确切的错误,我无法判断。 rules.yml 文件包含在 prometheus.yml 文件中,因此错误可能不在此文件中。
    猜你喜欢
    • 1970-01-01
    • 2021-07-13
    • 1970-01-01
    • 2021-11-09
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    • 2019-07-15
    相关资源
    最近更新 更多