Prometheus监控教程:配置介绍

发布时间 2023-03-28 10:55:20作者: 小学生II

转载:https://blog.csdn.net/guting18893110463/article/details/129656067?spm=1001.2014.3001.5502

Prometheus使用prometheus.yml配置文件进行全局变量、告警、规则等内容配置,在启动时指定相关的文件,对配置内容进行加载。

Prometheus的配置文件是YAML格式。Prometheus的解压包里自带了一个默认的配置文件prometheus.yml。

./prometheus --config.file=prometheus.yml
prometheus 定义了四个单元global、alerting、rule_files、scrape_configs

在配置文件中我们可以指定 global, alerting, rule_files, scrape_configs, remote_write, remote_read 等属性。

一、global(全局配置)

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: 10s # is set to the global default (10s).
external_labels:
monitor: 'codelab-monitor'
global 属于全局的默认配置,它主要包含 4 个属性:

scrape_interval: 拉取 targets 的默认时间间隔,即拉取业务监控数据的间隔时间。

scrape_timeout: 拉取一个 target 的超时时间,即拉取业务监控数据接口的超时时间。

evaluation_interval: 执行 rules 的时间间隔。即多久遍历一次告警规则列表,判断每个规则是否触发告警。和rule_files的加载没关系

external_labels: 额外的属性,会添加到拉取的数据并存到数据库中。

二、alerting(报警定义)
设定alertmanager和prometheus交互的接口,即alertmanager监听的ip地址和端口。

# Alertmanager configuration
alerting:
alertmanagers:
- scheme: http
timeout: 10s
- static_configs:
- targets:
# - alertmanager:9093
scheme:配置如何访问alertmanager,可使用http或https。

timeout:配置与alertmanager连接的超时时间。

static_configs:配置alertmanager的地址信息

三、rule_files
用于获取所有规则文件中的规则,包括记录规则(recording rules)与告警规则(alerting rule)。

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
四、scrape_configs
scrape_configs 主要用于配置拉取数据节点,每一个拉取配置主要包含以下参数:

job_name:任务名称

honor_labels:用于解决拉取数据标签有冲突,当设置为 true, 以拉取数据为准,否则以服务配置为准

params:数据拉取访问时带的请求参数

scrape_interval:拉取时间间隔

scrape_timeout: 拉取超时时间

metrics_path:拉取节点的 metric 路径

static_configs:配置访问路径前缀,如ip+port,或者域名地址,或者通过服务发现,类似alertmanager.prom-alert.svc:9093

scheme:拉取数据访问协议,如http

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'.
-scheme:'http'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
五、remote_write
remote_write 主要用于可写远程存储配置,主要包含以下参数:

url: 访问地址

remote_timeout: 请求超时时间

write_relabel_configs: 标签重置配置, 拉取到的数据,经过重置处理后,发送给远程存储

参考:

https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config
————————————————
版权声明:本文为CSDN博主「IT运维先森」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/guting18893110463/article/details/129656067