Promethues如何对进程监控

2022-06-07 09:13:33 浏览数 (1)

为了使Promethuse可以对进程进行监控,可以用利用process-exporter来检测所选进程的存活状态

一、安装process-exporter

  • 1、安装部署
代码语言:javascript复制
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
代码语言:javascript复制
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'

  • 监控所有服务进程 (可以忽略)
代码语言:javascript复制
process_names:
  - name: "{{.Comm}}"
    cmdline:
    - '. '
  • 命令参数解释:
  • 3、启动命令
代码语言:javascript复制
nohup /usr/local/exporter/process-exporter/process-exporter -config.path=/usr/local/exporter/process-exporter/process-exporter.yaml &

或者采用system制作启动文件

代码语言:javascript复制
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
代码语言:javascript复制
启动命令
systemctl daemon-reload
systemctl start process_exporter
systemctl enable process_exporter
  • 4、访问 curl localhost:9256/metrics

二、配置prometheus采集进程数据

  • 1、修改配置文件 vi /usr/local/prometheus/prometheus.yml
代码语言:javascript复制
 - job_name: 'process'
    static_configs:
    - targets: ['114.67.116.119:9256']
  • 2、重启动
代码语言:javascript复制
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同样名称,一个是系统空间,一个是用户空间

0 人点赞