1.1 下载Process-exporter并安装

  1. #下载Process_exporter
  2. [root@prometheus src]# wget wget https://github.com/ncabatoff/process-exporter/releases/download/v0.5.0/process-exporter-0.5.0.linux-amd64.tar.gz
  3. #解压并安装
  4. [root@prometheus src]# tar xf process-exporter-0.5.0.linux-amd64.tar.gz
  5. [root@prometheus src]# mv process-exporter-0.5.0.linux-amd64 ../
  6. [root@prometheus local]# mv process-exporter-0.5.0.linux-amd64/ process-exporter
  7. [root@prometheus local]# cat /etc/systemd/system/process-exporter.service
  8. [Unit]
  9. Description=node exporter
  10. Documentation=node exporter
  11. [Service]
  12. ExecStart=/usr/local/process-exporter/process-exporter -config.path /usr/local/process-exporter/process-name.yaml
  13. [Install]
  14. WantedBy=multi-user.target
  15. #3、配置文件匹配规则
  16. 配置文件根据变量名匹配到配置文件:
  17. {{.Comm}} 包含原始可执行文件的basename,/proc//stat 中的换句话说,2nd 字段
  18. {{.ExeBase}} 包含可执行文件的basename
  19. {{.ExeFull}} 包含可执行文件的完全限定路径
  20. {{.Matches}} 映射包含应用命令行tlb所产生的所有匹配项
  21. #4、创建监控服务器进程配置文件
  22. Process-exporter 可以进程名字匹配进程,获取进程信息。匹配规则由name对应的模板变量决定,以下表示监控进程名字为nginx(前提是我们已经安装了Nginx
  23. [root@prometheus local]# yum install epel* -y
  24. [root@prometheus local]# yum install nginx -y
  25. [root@prometheus local]# systemctl start nginx
  26. #5、配置nginx进程监控配置文件
  27. [root@prometheus process-exporter]# cat process-name.yaml
  28. process_names:
  29. - name: "{{.Matches}}"
  30. cmdline:
  31. - 'nginx'
  32. #6、启动process-exporter
  33. [root@prometheus process-exporter]# systemctl daemon-reload
  34. [root@prometheus process-exporter]# systemctl enable process-exporter
  35. [root@prometheus process-exporter]# systemctl start process-exporter
  36. [root@prometheus process-exporter]# ss -lntp|grep process
  37. LISTEN 0 128 :::9256 :::* users:(("process-exporte",pid=28543,fd=3))
  38. #7、配置prometheus文件
  39. [root@prometheus prometheus]# vim prometheus.yml
  40. - job_name: 'process'
  41. static_configs:
  42. - targets: ['10.4.7.58:9256']
  43. #8、重启prometheus服务
  44. [root@prometheus prometheus]# systemctl restart prometheus

image.png
发现process-exporter起来了

1.2 配置grafana

填写ID:249
image.png
image.png
image.png

最后的出图结果。

1.3 监控所有进程

  1. #配置yaml文件
  2. [root@prometheus process-exporter]# cat process-name.yaml
  3. process_names:
  4. - name: "{{.Matches}}"
  5. cmdline:
  6. - '.+'
  7. #重启客户端
  8. [root@prometheus process-exporter]# systemctl restart process-exporter

最后结果:
image.png