Skip to content

配置文件

1. prometheus.yml配置文件

大致分为四类

1.1 global配置块

yaml
global:
  scrape_interval: 2m
  scrape_timeout: 10s
  evaluation_interval: 4m
global:
  scrape_interval: 2m
  scrape_timeout: 10s
  evaluation_interval: 4m
参数描述
scrape_interval用来指定Prometheus从监控端抓取数据的时间间隔(默认为15s),如果在特定的job指定时间间隔指标,则该job的配置会覆盖全局设置
scrape_timeout拉取实例指标的超时时间
evaluation_interval用于指定检测告警规则的时间间隔,每15s重新检测告警规则,并对变更进行更新

1.2 Alertmanager配置块

官当

用于设置Prometheus与Alertmanager的通信,在Prometheus的整体架构中,Prometheus会根据配置的告警规则触发警报并发送到独立的Alertmanager组件,Alertmanager将对告警进行管理并发送给相关的用户。

yml
alerting:
  alertmanagers:
  - scheme: http
    timeout: 10s
    static_configs:
    - targets:
        - localhost:9093
alerting:
  alertmanagers:
  - scheme: http
    timeout: 10s
    static_configs:
    - targets:
        - localhost:9093
参数描述
scheme配置如何访问alertmanager,可使用http或https
timeout配置与alertmanager连接的超时时间
static_configs配置alertmanager的地址信息

1.3 rule_files配置块

用于指定告警规则的文件路径,文件格式为yml

yaml
rule_files:
  - "alert.yml" #单个文件
  - "rules/*.yml" #配置目录
rule_files:
  - "alert.yml" #单个文件
  - "rules/*.yml" #配置目录

1.4 scrape_config 配置块

官当

用于指定Prometheus抓取的目标信息

yml
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

https://yasongxu.gitbook.io/container-monitor/yi-.-kai-yuan-fang-an/di-2-zhang-prometheus/prometheus-de-pei-zhi-yu-fu-wu-fa-xian