Trying to configure prometheus with alert manager but getting error with rules file

て烟熏妆下的殇ゞ 提交于 2021-01-29 04:52:50

问题


In my prometheus.yml,the rules file is called rules.yml and it has this

---
groups:
  - name: example
    rules:
      - alert: ServiceDown
        expr: up == 0
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: cannot connect to {{ $labels.job }}

when i run sudo ./promtool check config rules.yml i get the error

Checking rules.yml
  FAILED: parsing YAML file rules.yml: yaml: unmarshal errors:
  line 2: field groups not found in type config.plain

I am not sure what is wrong as i am following this https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/

Prometheus version is 2.18.1

Hoping for some assistance from someone

Thanks KK


回答1:


You are loading the rules.yml using the "rule_file" clause in the Prometheus configuration file, right?

rule_files:
  - rules.yml

I notice that we can't execute the "promtool check config" directly to the rule file but if you execute it to the Prometheus configuration file it'll check the rule file correctly:

$ promtool check config prometheus.yaml

Checking prometheus.yaml
  SUCCESS: 1 rule files found

Checking rules.yaml
  SUCCESS: 18 rules found


来源:https://stackoverflow.com/questions/62058871/trying-to-configure-prometheus-with-alert-manager-but-getting-error-with-rules-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!