使用supervisor守护Prometheus进程
之前是将Prometheus组件注册为系统服务,要编辑好几个文件,没有shell脚本的时候手动配置比较麻烦,改用supervisor会方便不少。
只要supervisor启动,就会自动拉起Prometheus组件并守护进程。
安装supervisor
yum install -y supervisor
systemctl start supervisord && systemctl enable supervisord
安装Prometheus监控系统
- 节点:192.168.0.10
- 组件:
- prometheus server
- node_exporter
- alertmanager
- 钉钉告警插件
具体步骤可以参考其它文章,本文不做展开。
配置supervisor
-
vim /etc/supervisord.d/prometheus.ini
,内容如下:(注意修改路径、IP、端口、钉钉机器人的webhook)
[program:prometheus]
command=/usr/local/prometheus/prometheus/prometheus --storage.tsdb.path=/home/data/prometheus/prometheus/ --config.file=/usr/local/prometheus/prometheus/prometheus.yml --web.listen-address=:19090 --storage.tsdb.retention=15d
directory=/usr/local/prometheus/prometheus
autostart=true
startsecs=10
startretries=3
autorestart=true
[program:alertmanager]
command=/usr/local/prometheus/alertmanager/alertmanager --storage.path="/home/data/prometheus/alertmanager/" --web.listen-address=":18081" --config.file=/usr/local/prometheus/alertmanager/alertmanager.yml --data.retention=120h --web.external-url=http://192.168.0.10:18081
directory=/usr/local/prometheus/alertmanager
autostart=true
startsecs=10
startretries=3
autorestart=true
[program:dingtalk]
command=/usr/local/prometheus/dingtalk/prometheus-webhook-dingtalk --ding.profile="webhook1=https://oapi.dingtalk.com/robot/send?access_token=xxxx"
directory=/usr/local/prometheus/dingtalk
autostart=true
startsecs=10
startretries=3
autorestart=true
[program:nodeexporter]
command=/usr/local/prometheus/node_exporter/node_exporter --web.listen-address 0.0.0.0:18080
directory=/usr/local/prometheus/node_exporter
autostart=true
startsecs=10
startretries=3
autorestart=true
- 配置生效:
supervisorctl update
- 查看状态:
supervisorctl status
ps -ef | grep prometheus