MENU

Grafana+Prometheus+Process-exporter监控Linux系统服务进程

• 2021 年 02 月 22 日 • Grafana,Prometheus,监控分析

1.普通安装部署process-exporter

wget https://github.com/ncabatoff/process-exporter/releases/download/v0.4.0/process-exporter-0.4.0.linux-amd64.tar.gz

tar -xvf process-exporter-0.4.0.linux-amd64.tar.gz

进入到解压目录下编写配置文件

vim process-exporter-ncabatoff.yaml

 process_names:
   - name: "{{.Matches}}"
     cmdline:
     - 'redis-server'
   - name: "{{.Matches}}"
     cmdline:
     - 'mysqld'
   - 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'

注 cmdline: 所选进程的唯一标识,ps -ef 可以查询到。如果改进程不存在,则不会有该进程的数据采集到。

编写启动脚本

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=/opt/process-exporter-0.4.0.linux-amd64
ExecStart=/opt/process-exporter-0.4.0.linux-amd64/process-exporter -config.path=/opt/process-exporter-0.4.0.linux-amd64/process-exporter-ncabatoff.yaml
Restart=on-failure
[Install]
WantedBy=multi-user.target

加载启动process_exporter服务

systemctl daemon-reload

systemctl start process_exporter

systemctl enable process_exporter

2. Docker安装process-exporter

wget https://github.com/ncabatoff/process-exporter/releases/download/v0.5.0/process-exporter-0.5.0.linux-amd64.tar.gz
tar -xvf  process-exporter-0.5.0.linux-amd64.tar.gz -C /usr/local/

3. 创建配置文件

Process-Exporter的做法是配置需要监控的进程的名称,他会去搜索该进程从而得到其需要的监控信息,其实也就是我们常做的“ps -efl | grep xxx”命令来查看对应的进程。

配置文件一开始是不存在的,需要我们创建,名字可以自定义:

vim process-name.yaml
process_names:
  - name: "{{.Matches}}"
    cmdline:
    - 'nginx'

  - name: "{{.Matches}}"
    cmdline:
    - 'zombie'

也可以定义全部:

vim conf.yaml
process_names:
  - name: "{{.Comm}}"
    cmdline:
    - '.+'

4. 重启服务

./process-exporter -config.path process-name.yaml &

5. 查看数据

curl http://localhost:9256/metrics

6. Grafana 画图

https://grafana.com/grafana/dashboards/8378

返回文章列表 文章二维码 打赏
本页链接的二维码
打赏二维码