网站首页 > 精选文章 / 正文
基本概念
Prometheus 是一个开源的监控系统,通过“拉取”的方式从被监控的目标系统中采集指标数据并存储,通过查询语言(PromQL)进行数据分析。
Node Exporter 是 Prometheus 官方提供的一个监控 Linux 系统的导出器(exporter)。运行在被监控主机上,将该主机的系统指标(CPU 使用率、内存使用情况、磁盘 IO 和网络流量等。)以 HTTP 接口的形式暴露给 Prometheus。
Alertmanager负责管理和路由告警通知。具体来说,Prometheus 根据配置的告警规则,在满足条件时向 Alertmanager 发送告警,Alertmanager 再将告警消息发送到预先配置的通知渠道(如邮件、短信、Slack 等)。
Grafana 是一个开源的数据可视化工具,可以将多种数据源(包括 Prometheus)中的监控数据转化为直观的仪表板。
总得来说,Prometheus 是核心,Node Exporter 为 Prometheus 提供主机数据,Alertmanager 执行告警通知,Grafana 将数据进行展示和分析。
Job是一组监控目标的逻辑集合,可以理解为一种服务或应用。比如你可能会有一个 job 名为 app_server,其中包含多个实例(服务器),用于监控应用服务器集群的健康状况。
instance 表示服务的具体实例(通常是地址),用于识别每个实际监控的目标。比如在 job 为 app_server 的情况下,可能有多个 instance,如 app-server-1:9100、app-server-2:9100,分别代表不同的服务器。
Prometheus二进制安装
cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.45.5/prometheus-2.45.5.linux-amd64.tar.gz
tar xvfz prometheus-2.45.5.linux-amd64.tar.gz
mv prometheus-2.45.5.linux-amd64 /opt/prometheus
[root@FNSHB109 blueadmin]# cat /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
ExecStart=/opt/prometheus/prometheus-2.45.5.linux-amd64/prometheus \
--config.file=/opt/prometheus/prometheus-2.45.5.linux-amd64/prometheus.yml \
--storage.tsdb.path=//opt/prometheus/prometheus-2.45.5.linux-amd64/data
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus
systemctl status Prometheus
访问地址:http://10.101.12.28:9090/
alertmanager二进制安装
wget https://github.com/prometheus/alertmanager/releases/download/v0.27.0/alertmanager-0.27.0.linux-amd64.tar.gz
tar xvfz alertmanager-0.27.0.linux-amd64.tar.gz
mv alertmanager-0.27.0.linux-amd64 /opt/prometheus/
[root@FNSHB109 blueadmin]# cat /etc/systemd/system/alertmanager.service
[Unit]
Description=alertmanager server daemon
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
[Service]
ExecStart=/opt/prometheus/alertmanager-0.27.0.linux-amd64/alertmanager --config.file=/opt/prometheus/alertmanager-0.27.0.linux-amd64/alertmanager.yml --storage.path=/opt/prometheus/alertmanager-0.27.0.linux-amd64/data
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start alertmanager.service
systemctl status alertmanager.service
访问地址:http://10.101.12.28:9093/
grafana安装
wget https://dl.grafana.com/oss/release/grafana-9.3.16-1.x86_64.rpm
yum localinstall grafana-9.3.16-1.x86_64.rpm
service grafana-server start
service grafana-server status
访问地址:http://10.101.12.28:4000/
node_exporter二进制安装
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz
tar xvfz node_exporter-1.8.1.linux-amd64.tar.gz
mv node_exporter-1.8.1.linux-amd64 /opt/prometheus/
[root@FNSHB109 blueadmin]# cat /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/opt/prometheus/node_exporter-1.8.1.linux-amd64/node_exporter
[Install]
WantedBy=default.target
systemctl daemon-reload
systemctl start node_exporter
systemctl status node_exporter
访问地址:http://10.101.12.28:9100/
prometheus.yml
[root@FNSHB109 prometheus-2.45.5.linux-amd64]# grep -v ^$ /opt/prometheus/prometheus-2.45.5.linux-amd64/prometheus.yml|grep -v ^#
global:
scrape_interval: 15s #默认抓取时间间隔设置为 15 秒
evaluation_interval: 15s # 默认规则评估间隔设置为 15 秒
# scrape_timeout is set to the global default (10s). 默认的 scrape_timeout 为 10 秒,即 Prometheus 会等待 10 秒以确保抓取完成。
alerting: # 配置了一个 Alertmanager 实例,运行在本地的 9093 端口。
#当告警条件满足时,Prometheus 将告警发送到该 Alertmanager,以便执行告警通知和路由。
alertmanagers:
- static_configs:
- targets:
- localhost:9093
rule_files: #rule_files:定义了 Prometheus 使用的告警规则文件。
- "alert.yml"#这里激活了一个规则文件 alert.yml,
scrape_configs:# scrape_configs用于定义 Prometheus 需要抓取的服务(称为 Job)
- job_name: "prometheus"#将此作业命名为 prometheus,即 Prometheus 自身的指标。
static_configs:# 从 localhost:9090 抓取数据(Prometheus 默认在 9090 端口上暴露自身的指标)。
- targets: ["localhost:9090"]
- job_name: "node-exporter"#此作业用于抓取 node-exporter 的指标。
scrape_interval: 15s
static_configs:
- targets: ["localhost:9100"]#抓取本地 9100 端口上的 node-exporter 指标。
labels:
instance: prometheus-service#为该目标添加标签 instance: prometheus-service,可以帮助区分不同的实例。
alert.yml
此配置将在 Prometheus 监控的实例 up 值为 0 且持续 30 秒时,触发一个名为 warn 的告警。
[root@FNSHB109 prometheus-2.45.5.linux-amd64]# cat alert.yml
groups:
- name: alert # 告警组的名称,可以包含多个规则
rules:
- alert: warn # 告警名称,可以随意指定,通常描述告警类型或级别
expr: up==0 # 表达式,表示如果某个实例的 `up` 值为 0(即实例不可用),则触发告警
for: 30s # 触发告警的持续时间。如果 `up==0` 持续 30 秒,才会触发告警
labels:
severity: 'critical' # 设置告警的严重级别为 "critical"
annotations: #告警的附加信息,可以在通知中显示,用于详细描述告警上下文:
instance: "instance:{{ $labels.instance }}"#使用模板变量 {{ $labels.instance }} 动态显示出具体的不可用实例。
description: "{{ $labels.job }}"# 显示不可用实例的 job 标签值
Tags:alertmanager配置详解
猜你喜欢
- 2024-11-30 Prometheus+Node_exporter+Grafana+Alertmanager 监控部署(上)
- 2024-11-30 Prometheus监控利器介绍
- 2024-11-30 基于Prometheus的企业监控报警平台
- 2024-11-30 基于 Prometheus 的监控神器,简单灵活
- 2024-11-30 超干货!开源监控系统 Prometheus 最佳实践
- 2024-11-30 Prometheus和AlertManager的告警机制
- 2024-11-30 Prometheus监控系统
- 2024-11-30 想吃透监控系统,就这一篇够不够?
- 2024-11-30 微服务平台建设方案
- 2024-11-30 掌握Web应用的监控与告警