Prometheus 添加规则文件后没有启动

Posted

技术标签:

【中文标题】Prometheus 添加规则文件后没有启动【英文标题】:Prometheus not started after adding rule file into it 【发布时间】:2019-07-17 05:23:02 【问题描述】:

添加规则文件后,我添加了简单的规则以从节点导出器获取可用磁盘空间

prometheus.yml

文件,prometheus 没有启动,可能是规则文件的问题。

# my global config
global:
  scrape_interval:     60s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 60s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
       - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - 'low-disk-space.rules'
  # - 'sample-rules.yml'
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  #- job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    #static_configs:
    #- targets: ['localhost:9090']

  - job_name: 'machine'
    static_configs:
    - targets: ['localhost:9100']

我的规则文件如下所示:

groups:
  - name: disk_usage
    interval: 5s
    rules:
    - record: node_exporter:node_filesystem_free:fs_used_percents
      expr: 100 - 100 * ( node_filesystem_freemountpoint="/" / node_filesystem_sizemountpoint="/" )

    - name: alerting_rules
      rules:
        - alert: DiskSpace10%Free
          expr: node_exporter:node_filesystem_free:fs_used_percents >= 90
          labels:
            severity: moderate
          annotations:
            summary: "Instance  $labels.instance  is low on disk space"
            description: " $labels.instance  has only  $value % free."

普罗米修斯版本:2.3.2 在此处发布了有关规则文件验证的另一个问题 how to install latest version of prometheus/promtool in ubuntu?

【问题讨论】:

【参考方案1】:

您的规则文件缩进稍微偏离了一点,第二部分 (alerting_rules) 缩进太远,请尝试将其与 disk_usage 记录规则相提并论。

groups:
  - name: disk_usage
    interval: 5s
    rules:
    - record: node_exporter:node_filesystem_free:fs_used_percents
      expr: 100 - 100 * ( node_filesystem_freemountpoint="/" / node_filesystem_sizemountpoint="/" )

  - name: alerting_rules
    rules:
      - alert: DiskSpace10%Free
        expr: node_exporter:node_filesystem_free:fs_used_percents >= 90
        labels:
          severity: moderate
        annotations:
          summary: "Instance  $labels.instance  is low on disk space"
          description: " $labels.instance  has only  $value % free."

【讨论】:

以上是关于Prometheus 添加规则文件后没有启动的主要内容,如果未能解决你的问题,请参考以下文章

使用 Prometheus 监控 eKuiper 规则运行状态

Prometheus 2.17.0 新特性

Prometheus 2.17.0 新特性

Prometheus部署告警对接邮箱

Prometheus部署告警对接邮箱

prometheus配置alertmanager完整过程