Prometheus 监控进程

Posted bigberg

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Prometheus 监控进程相关的知识,希望对你有一定的参考价值。

Process-exporter

  process-exporter可以用来检测所选进程的存活状态

下载process-exporter

  下载地址:https://github.com/ncabatoff/process-exporter/releases/tag/v0.4.0  

安装部署process-exporter

tar -zxvf process-exporter-0.4.0.linux-amd64.tar.gz -C /usr/local/process-exporter

  编写配置文件

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=/usr/local/process-exporter
ExecStart=/usr/local/process-exporter/process-exporter -config.path=/usr/local/process-exporter/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

  

验证

curl localhost:9256/metrics

  

修改Prometheus配置文件

增加

 - job_name: ‘process‘
    static_configs:
    - targets: [‘172.16.8.187:9256‘]

  重启Prometheus

  技术分享图片

 

以上是关于Prometheus 监控进程的主要内容,如果未能解决你的问题,请参考以下文章

技术分享| 如何使用Prometheus实现系统进程监控

技术分享| 如何使用Prometheus实现系统进程监控

Prometheus监控指标的label注入方法

nodejs fork 子进程创建任务以及简单的prometheus 监控

通过Prometheus和Grafana监控Linux进程

prometheus能监控哪些指标