Prometheus配置文件详解
概述
Prometheus是一个开源的系统监控和警报工具包。它的配置文件通常命名为prometheus.yml,用于配置Prometheus服务器的行为。
其配置文件主要包含以下几个部分:
global: 全局配置
alerting: 警报配置
rule_files: 规则文件配置
scrape_configs: 抓取配置(用于配置监控目标)
remote_write, remote_read: 远程读写配置(用于与远程存储集成)
global(全局配置)
定义整个 Prometheus 实例的默认行为
示例:
global:
# 设定 Prometheus 抓取目标实例指标数据的时间间隔,默认 1m ,可按需修改,如设为 15s 实现更频繁采集 。
scrape_interval: 15s
# Prometheus 评估告警规则的时间间隔,默认 1m ,即每 1 分钟检查告警规则是否触发。
evaluation_interval: 15s
# 一次抓取请求的超时时间,默认 10s ,超时则抓取失败
scrape_timeout: 10s
# 与外部系统(联邦、远程存储、Alertmanager 等 )通信时,添加到度量指标数据的标签,用于标识监控源等信息。
external_labels:
cluster: "prod"
region: "us-west"
rule_files(规则文件配置)
指定告警规则文件路径列表,支持通配符。Prometheus 从中读取告警规则
示例:
rule_files:
- "rules/alerts.yml" # 警报规则路径
- "rules/*.rules" # 支持通配符
规则文件示例 (rules/alerts.yml):
groups:
- name: example-alerts
rules:
- alert: HighCPU
expr: avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) < 0.2
for: 10m
labels:
severity: critical
annotations:
summary: "高CPU使用率 ({{ $labels.instance }})"
alerting(警报配置)
关联 Alertmanager 实例
alertmanagers:
- scheme: http
# 发送警报超时时间
timeout: 10s
# Alertmanager实例地址
static_configs:
- targets:
- "127.0.0.1:9093"
scrape_configs(抓取配置)
核心部分,用于定义监控目标及数据抓取方式。
scrape_configs:
# Job 名称(唯一标识)
- job_name: "prometheus"
# 静态目标列表
static_configs:
# 目标地址 (host:port)
- targets: ["localhost:9090"]
- job_name: "node_exporter"
# 协议 (http/https, 默认http)
scheme: https
# 指标路径(默认为 /metrics)
metrics_path: /metrics
# 请求参数
params:
module: [net]
# 目标地址
static_configs:
- targets: ["10.0.0.1:9100", "10.0.0.2:9100"]
# 抓取前重写标签
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
# 抓取后重写指标标签
metric_relabel_configs:
- source_labels: [device]
regex: "^(/dev/sd.).*"
replacement: "$1"
action: replace
remote_write&remote_read(远程读写配置)
远程写入配置(remote_write)
配置将 Prometheus 采集数据远程写入其他存储系统的参数,如:
- url:远程存储写入地址。
- remote_timeout:远程写入请求超时时间,默认 30s 。
- 还包括 tls_config(TLS 配置)、basic_auth(认证配置 )、write_relabel_configs(对要远程写入数据重新标记 )等配置项。
远程读取配置(remote_read)
配置从远程存储读取数据的相关参数,与 remote_write 类似 ,如 url(读取地址) 、read_recent(是否仅读取最近数据 )、required_matchers(读取数据必须匹配的标签条件 )等。
热加载配置文件
修改了配置文件之后,我们不想重启Prometheus,想让其进行热加载配置文件,应该怎么做呢?
前提条件,启动Prometheus时需要开启热加载,需要指定该参数:--web.enable-lifecycle
访问下面的接口即可
curl -X POST http://localhost:9090/-/reload
热加载之前可以使用promtool工具对你的配置文件修改进行检查
[root@lb ~/prometheus]# ./promtool check config prometheus.yml
Checking prometheus.yml
SUCCESS: prometheus.yml is valid prometheus config file syntax
Prometheus配置文件详解的更多相关文章
- Prometheus 配置文件详解
Prometheus 配置文件详解 官方文档:https://prometheus.io/docs/prometheus/latest/configuration/configuration/ 指标说 ...
- quartz配置文件详解
quartz配置文件详解(转载) quartz学习总结: 一.关于job: 用Quartz的行话讲,作业是一个执行任务的简单Java类.任务可以是任何Java代码.只需你实现org.qu ...
- WebConfig配置文件详解
今天看到博客园一位朋友整理的一个WebConfig配置文件详解,觉得不错,转载一下: <?xml version="1.0"?> <!--注意: 除了手动编辑此文 ...
- tomcat配置文件详解
Tomcat系列之服务器的安装与配置以及各组件详解 tomcat 配置文件详解
- ubuntu nginx 安装以及配置文件详解
1.到nginx官网下载源码包.最好下载稳定版本,nginx官网http://www.nginx.org/ 2.安装nginx依赖包运行命令: sudo apt-get install libssl- ...
- Spring配置文件详解 – applicationContext.xml文件路径
Spring配置文件详解 – applicationContext.xml文件路径 Java编程 spring的配置文件applicationContext.xml的默 ...
- spring配置文件详解--真的蛮详细
spring配置文件详解--真的蛮详细 转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常 ...
- net-snmp配置文件详解
net-snmp配置文件详解 net-snmp的配置文件是有一定的层次结构的,配置起来也很方便.网上找了很多资料,大概把这个配置文件的各个信息搞懂了一点.其实在net-snmp的EXAMPLE.con ...
- Rsyslog配置文件详解
Rsyslog配置文件详解https://my.oschina.net/0757/blog/198329 # Save boot messages also to boot.log 启动的相关信息lo ...
- (原创)LAMP搭建之二:apache配置文件详解(中英文对照版)
LAMP搭建之二:apache配置文件详解(中英文对照版) # This is the main Apache server configuration file. It contains the # ...
随机推荐
- postman 如何比较两台电脑的脚本是否一样
- Linux 安装 MySQL 8.0
目录 下载 安装数据库 修改mysql配置文件(若没有则新建) 安装并初始化mysql 查看mysql密码 配置启动 登录MySQL 修改密码 配置远程连接 配置防火墙 常见错误 Windows 安装 ...
- 【Bug记录】[@vue/compiler-sfc] `defineProps` is a compiler macro and no longer needs to be imported.
[Bug记录][@vue/compiler-sfc] defineProps is a compiler macro and no longer needs to be imported. Vue3项 ...
- dify 1.0.1无法在ollama下新增LLM模型
原来在0.15很正常,升到1.0.0之后就不行 了,再后来1.0.1出来后,以为问题都解决了,没想到还是有问题. 具体是:添加ollama是容易了,但是添加模型(比如deepsek)还是不行.表现为点 ...
- 利用队列的内置模块(deque)模拟 Linux 下的 tail 命令(输出文件中最后几行的内容)
博客地址:https://www.cnblogs.com/zylyehuo/ # -*- coding: utf-8 -*- from collections import deque def tai ...
- String常见面试题
第一题:打印的结果是true还是false呢? 在之前我们就说过这题,执行s1时,检查字符串常量池,发现没有"abc",于是创建"abc",执行s2时,接着检查 ...
- DevOps工程师技能
技术背景 DevOps工程师必须持有计算机科学.工程或其他相关领域的学位.2年以上工作经验.这包括开发人员.系统管理员或devops驱动的团队成员的工作.这是一个重要的需求,同时也是对所有IT操作的理 ...
- 快速理解 MCP 与 A2A 协议的关系,它们如何协作构建复杂AI系统
近期关于MCP协议的讨论非常热门,主要因为通过MCP协议通过标准化接口为 AI 应用与外部数据源建立统一交互通道,这使得大模型可以与外部数据源或工具进行交互,从而实现各种专业场景下的智能应用.关于如何 ...
- 掌握Tortoise-ORM高级异步查询技巧
title: 掌握Tortoise-ORM高级异步查询技巧 date: 2025/04/22 12:05:33 updated: 2025/04/22 12:05:33 author: cmdrago ...
- mac系统安装GNU-sed
经过网上查资料,发现 由于 mac 系统与 linux 系统的差异,mac自带的sed命令,因为其是基于bsd,所以与常用的gnu不一样,安装gnu-sed 可正常使用: 1.brew install ...