当运行Prometheus时,我们会通过--config.file配置项来指定Prometheus配置文件(Prometheus.yml)。Prometheus自带默认的配置文件Prometheus.yml,该配置文件位于上一章解压目录中。那我们来看看它的内容吧。
去到部署的配置目录
$ cd /application/prometheus/
$ pwd
/application/prometheus
$ cat prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # 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:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
global
Global模块是全局配置信息,它定义的内容会被scrape_configs模块中的每个Job单独覆盖
- scrape_configs:该参数来指定应用程序或服务抓取数据的间隔时间。这个值是时间序列的颗粒度,即该序列中每个数据点所覆盖的时间段。
- evaluation_interval:该参数来指定Prometheus评估规则的频率。目前主要有两种规则:记录规则(recording)和告警规则(alerting rule)。
- 记录规则:允许预先计算使用频繁且开销大的表达式,并将结果保存为一个新的时间序列数据。
- 告警规则:允许定义告警条件。
- scrape_timeout:抓取target的超时时间,默认值为10秒
- external_labels:与外部系统通信时添加到任意时间序列或告警所用的外部标
alerting
alerting用来配置Prometheus告警系统AlertManager,当触发告警规则后,Prometheus会将告警信息发送给AlertManager进行告警通知。
- alertmanagers:该参数下会列出Prometheus使用的每个AlertManager
- static_confgs:该参数用于静态配置AlertManager的地址,也可以依赖服务发现动态识别
- targets:该参数下是各个AlertManager的地址,可以配置多个地址
rule_files
rule_files参数是用来指定记录规则与告警规则的配置文件列表。
scrape_confgs
scrape_configs参数用来配置Prometheus抓紧的所有目标。
- job_name:该参数来指定抓取任务名称,Prometheus会将该名称作为Label追加到抓紧每天时序中
- metrics_path:该参数用来自定义抓取指标的http path
- scheme:该参数用来指定抓取指标协议,默认是http
- param:该参数用来指定抓取指标相关参数
- static_confgs:该参数用于静态配置抓取目标的地址,也可以依赖服务发现动态识别
本文详细解读了Prometheus配置文件Prometheus.yml的内容,包括全局设置(如scrape_interval和evaluation_interval)、告警管理器配置、规则文件、scrape_config的结构以及job_name、metrics_path等关键参数。
4

被折叠的 条评论
为什么被折叠?



