前言
客户端安装及配置
Premetheus服务端配置
模板导入
grafana效果图
前言
此场景主要是利用process-export监控主机的进程存活、资源占用率,防止进程挂掉导致服务崩溃
gitlab地址:GitHub - ncabatoff/process-exporter: Prometheus exporter that mines /proc to report on selected processes
tgz包:
process-exporter 下载地址
process-exporter-0.7.5.linux-amd64.tar.gz
客户端安装及配置
1.将包上传至/opt目录
2.tar -zxvf解压
3.mv重命名为 process-exporter
4.touch一个规则文件:process_name.yaml
如下截图:
编辑规则文件:
当前要监控的进程是vsftpd
vim /opt/process-exporter/process_name.yaml
process_names:
- name: "{{.Matches}}"
cmdline:
- 'vsftpd' #唯一标识
- name: "{{.Matches}}"
cmdline:
- 'httpd' #唯一标识
规则参数解释:
启动脚本配置:
[root@bogon /opt/process-exporter]# cat /usr/lib/systemd/system/process_exporter.service
[Unit]
Description=Prometheus exporter for processors metrics, written in Go with pluggable metric collectors.
Documentation=https://github.com/ncabatoff/process-exporter
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/process-exporter
ExecStart=/opt/process-exporter/process-exporter -config.path=/opt/process-exporter/process_name.yaml
Restart=on-failure
[Install]
WantedBy=multi-user.target
加入开机自启:
systemctl daemon-reload
systemctl start process_exporter
systemctl enable process_exporter
Premetheus服务端配置
添加targets,端口为9256
测试端口:established表示建立连接
添加进程告警规则:
- alert: 进程重启告警
expr: ceil(time() - max by(cluster, job, instance, groupname) (namedprocess_namegroup_oldest_start_time_seconds)) < 60
for: 30s
labels:
label: alert_once
severity: warning
annotations:
value: 进程 {{ $labels.groupname }} 在 {{ $value }} 秒前发生重启
- alert: 进程退出告警
expr: up{export="process_exporter"} == 0 or max by(cluster, job, instance, groupname) (delta(namedprocess_namegroup_oldest_start_time_seconds{groupname=~"^map.*"}[10d])) < 0
for: 60s
labels:
severity: warning
annotations:
value: 进程 {{ $labels.export}} 已退出
重启prometheus,我这边是docker部署,所以方式是:
docker restart monitor_prometheus_1
docker restart prometheus-alert
模板导入
Named processes by host | Grafana Labs
下载这个json后导入
grafana效果图
部署prometheus可以参考文章:
docker部署监控Prometheus+Grafana_docker安装prometheus grafana-CSDN博客
docker-compose部署Prometheus+Alertmanager并配置企业微信告警_alertmanager docker-compose-CSDN博客
Docker部署Prometheus+AlertManager实现邮件告警_docker部署的prometheus如何发送告警-CSDN博客
prometheus 监控告警系统(对接飞书告警)_prometheus-operator 飞书告警-CSDN博客
prometheus+alertmanager告警消息对接企业微信、飞书、钉钉_alertmanager对接企业微信-CSDN博客