为了使Promethuse可以对进程进行监控,可以用利用process-exporter来检测所选进程的存活状态
一、安装process-exporter
-
1、安装部署
wget https://github.com/ncabatoff/process-exporter/releases/download/v0.6.0/process-exporter-0.6.0.linux-amd64.tar.gz tar zxvf process-exporter-0.6.0.linux-amd64.tar.gz mv process-exporter-0.6.0.linux-amd64 /usr/local/exporter/process-exporter
-
2、配置文件,监控特定进程 vi /usr/local/exporter/process-exporter/process-exporter.yaml
process_names:
- name: "{{.Matches}}" cmdline: - 'redis-server'
-
name: "{{.Matches}}" cmdline:
- 'mysqld'
-
name: "{{.ExeFull}}" cmdline:
- '/usr/bin/mongod -f /etc/mongod.conf'
-
name: "{{.Matches}}" cmdline:
- 'org.apache.zookeeper.server.quorum.QuorumPeerMain'
-
name: "{{.Matches}}" cmdline:
- 'org.apache.hadoop.mapreduce.v2.hs.JobHistoryServer'
-
name: "{{.Matches}}" cmdline:
- 'org.apache.hadoop.hdfs.qjournal.server.JournalNode'
-
监控所有服务进程 (可以忽略)
process_names: - name: "{{.Comm}}" cmdline: - '.+'
命令参数解释:
-
3、启动命令
nohup /usr/local/exporter/process-exporter/process-exporter -config.path=/usr/local/exporter/process-exporter/process-exporter.yaml &
或者采用system制作启动文件
vim /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=prometheus
WorkingDirectory=/usr/local/exporter/process-exporter
ExecStart=/usr/local/exporter/process-exporter/process-exporter -config.path=/usr/local/exporter/process-exporter/process-exporter.yaml
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动命令
systemctl daemon-reload
systemctl start process_exporter
systemctl enable process_exporter
- 4、访问 curl localhost:9256/metrics
二、配置prometheus采集进程数据
-
1、修改配置文件 vi /usr/local/prometheus/prometheus.yml
- job_name: 'process'
static_configs:
- targets: ['114.67.116.119:9256']
- job_name: 'process'
static_configs:
-
2、重启动
kill 26765 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml 或者 kill -hup 26765
-
3、访问web
三、配置grafna展示数据
process-exporter对应的dashboard为:https://grafana.com/grafana/dashboards/249 注意:CPU一栏有2同样名称,一个是系统空间,一个是用户空间