本人配置的时候 观看了很多配置的文章 以下只是自己的配置笔记
这是比较有帮助的文章
https://www.cnblogs.com/anay/p/11871018.html
https://blog.csdn.net/aixiaoyang168/article/details/98474494
Prometheus下载地址
https://prometheus.io/download/
tar -xvf prometheus-2.17.1.linux-amd64.tar.gz
mv prometheus-2.17.1.linux-amd64 prometheus-2.17.1
cd /prometheus-2.17.1
修改配置文件
# 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告警的配置 xxxxxx:9093 是指向Alertmanager的地址
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- xxxxxx:9093
# 这是告警规则
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'
static_configs:
- targets: ['localhost:9090']
- job_name: 'redis_exporter_targets'
static_configs:
- targets:
- redis://localhost:6379
- redis://xxxxx:6379
metrics_path: /metrics
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: xxxxxxx:9121
- job_name: 'redis_exporter'
static_configs:
- targets:
- xxxxxxx:9121
- job_name: 'mysql'
static_configs:
- targets: ['xxxxxxx:9104']
labels:
instance: xxxxxxx:3306
- job_name: node_exporter
scrape_interval: 30s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- xxxxxx:9100
- xxxxxx:9100
- job_name: 'zhongcheng'
metrics_path: '/actuator/prometheus'
scrape_interval: 5s
static_configs:
- targets: ['xxxxxx:8088']
检查配置:
[root@localhost prome]# ./promtool check config prometheus.yml
Checking prometheus.yml
SUCCESS: 1 rule files found
Checking rules.yml
SUCCESS: 1 rules found
启动
–config.file=/app/prometheus-2.17.1/prometheus.yml #配置文件位置
–web.enable-lifecycle #开启热启动
./prometheus --config.file=/app/prometheus-2.17.1/prometheus.yml --web.enable-lifecycle
Alertmanager 下载地址
https://prometheus.io/download/
tar -xvf alertmanager-0.20.0.linux-amd64.tar.gz
mv alertmanager-0.20.0.linux-amd64 alertmanager-0.20.0
cd /alertmanager-0.20.0
配置文件
global:
resolve_timeout: 5m
smtp_smarthost: 'smtp.163.com:25' # 定义163邮箱服务器端
smtp_from: 'gudaoyufu@163.com' #来自哪个邮箱发的
smtp_auth_username: 'gudaoyufu@163.com' 邮箱验证
smtp_auth_password: 'XXXXXXXX' # 邮箱授权码,不是登录密码
smtp_require_tls: false # 是否启用tls
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 3m # 发送告警后间隔多久再次发送,减少发送邮件频率
receiver: 'mail' #发送的告警媒体
receivers:
- name: 'mail' # 接收者配置,这里要与接收媒体一致
email_configs:
- to: 'gudaoyufu@163.com' #发送给谁的邮箱,多个人多行列出
#inhibit_rules:
# - source_match:
# severity: 'critical'
# target_match:
# severity: 'warning'
# equal: ['alertname', 'dev', 'instance']
检查配置:
[root@localhost alertmanager]# ./amtool check-config alertmanager.yml
Checking 'alertmanager.yml' SUCCESS
Found:
- global config
- route
- 0 inhibit rules
- 1 receivers
- 0 templates
启动alertmanager
[root@localhost alertmanager]# ./alertmanager --config.file=./alertmanager.yml &
Alertmanager 配置告警规则文件
放在prometheus.yml 配置文件的同级目录中
开启prometheus.yml中的配置
直接重启prometheus即可 因为部署prometheus时开启了热重启 直接
然后热重启:curl -XPOST http://localhost:9090/-/reload
prometheus热重启
prometheus启动命令添加参数 --web.enable-lifecycle