process 进程监控
常见的进程监控配置
查看监控状态
process_exporter.service
root@ph-drt-v-66-232-live:~# systemctl status process_exporter.service
● process_exporter.service - Process Exporter for Prometheus
Loaded: loaded (/etc/systemd/system/process_exporter.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-12-19 16:51:27 +08; 1min 29s ago
Main PID: 3162795 (process_exporte)
Tasks: 11
Memory: 7.0M
CGroup: /system.slice/process_exporter.service
└─3162795 /usr/local/bin/process_exporter --config.path /etc/process_exporter/config.yml --web.listen-address=0.0.0.0:9118
12月 19 16:51:27 ph-drt-v-66-232-live systemd[1]: Started Process Exporter for Prometheus.
12月 19 16:51:27 ph-drt-v-66-232-live process_exporter[3162795]: 2022/12/19 16:51:27 Reading metrics from /proc based on "/etc/process_exporter/config.yml"
查看监控服务
root@ph-drt-v-66-232-live:~# cat /etc/systemd/system/process_exporter.service
[Unit]
Description=Process Exporter for Prometheus
After=network-online.target
[Service]
Type=simple
KillMode=process
ExecStart=/usr/local/bin/process_exporter \
--config.path /etc/process_exporter/config.yml \
--web.listen-address=0.0.0.0:9118
SyslogIdentifier=process_exporter
Restart=always
RestartSec=1
[Install]
WantedBy=multi-user.target
查看进程监控的配置
root@ph-drt-v-66-232-live:~# cat /etc/process_exporter/config.yml
process_names:
- comm:
- squid
- prometheus
- alertmanager
- nginx
- haproxy
- redis-server
- etcd
- bankapi
- coredns
- name: elasticsearch
comm:
- java
cmdline:
- org.elasticsearch.bootstrap.Elasticsearch
- name: zookeeper
comm:
- java
cmdline:
- org.apache.zookeeper.server.quorum.QuorumPeerMain
- name: kafka
comm:
- java
cmdline:
- kafka.Kafka
- name: bankapi
comm:
- java
cmdline:
- bank-gateway-adapter
查看进程数
root@ph-drt-v-66-231-live:~# curl 0.0.0.0:9118/metrics|grep bankapi|grep namedprocess_namegroup_num_procs
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 50533 100 50533 0 0 2467k 0 --:--:-- --:--:-- --:--:-- 2467k
namedprocess_namegroup_num_procs{groupname="bankapi"} 1