prometheus监控容器标签(Prometheus之使用process-exporter来监控服务进程)
process-exporter主要用来做进程监控,比如某个服务的进程数、消耗了多少CPU、内存、IO资源等。
1、process-exporter,可从github中搜索下载,process-exporter非官方出品,但能基本满足我们对进程监控的需求。
# wget https://github.com/ncabatoff/process-exporter/releases/download/v0.7.2/process-exporter-0.7.2.linux-amd64.tar.gz
# tar -xvf process-exporter-0.7.2.linux-amd64.tar.gz -C /usr/local/
# cd /usr/local/
# ln -s process-exporter-0.7.2.linux-amd64 process_exporter
# cd process_exporter
# ln -s process-exporter process_exporter
注:修改目录名,统一风格
2、创建配置文件,并添加要监控的进程
# cat /usr/local/process_exporter/config.yaml
process_names:
- name: "{{.Matches}}"
cmdline:
- '/usr/local/prometheus/prometheus'
- name: "{{.Matches}}"
cmdline:
- '/usr/local/alertmanager/alertmanager'
- name: "{{.Matches}}"
cmdline:
- '/usr/local/node_exporter/node_exporter'
- name: "{{.Matches}}"
cmdline:
- '/usr/bin/supervisord -c /etc/supervisord.conf'
3、使用systemd方式启动process_exporter
# cat > /lib/systemd/system/process_exporter.service <<EOF
[Unit]
Description=process-exporter
[Service]
ExecStart=/usr/local/process_exporter/process_exporter -config.path=/usr/local/process_exporter/config.yaml
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
启动process_exporter服务,并设置开机自启动
# systemctl daemon-reload
# systemctl enable process_exporter
# systemctl start process_exporter
默认端口:9256
4、将process_exporter做为target添加到prometheus中并加载配置
# vim /usr/local/prometheus/prometheus.yml
- job_name: 'process_exporter'
static_configs:
- targets: ['monitor01:9256']
labels:
app: process_exporter
nodename: monitor01
role: process_exporter
然后使用supervisorctl命令update下配置即可
# supervisorctl -uadmin -p1235 update
5、在prometheus控制台进行查询验证。
namedprocess_namegroup_num_procs,用于进程数监控
例如:namedprocess_namegroup_num_procs{groupname=~".*prometheus.*"}
namedprocess_namegroup_cpu_seconds_total,进程所占CPU监控,包括system和user两类
例如:sum(rate(namedprocess_namegroup_cpu_seconds_total{groupname=~".*prometheus.*"}[2m]))
namedprocess_namegroup_memory_bytes,进程所常驻内存监控
例如:namedprocess_namegroup_memory_bytes{groupname=~".*prometheus.*", memtype="resident"}
namedprocess_namegroup_read_bytes_total,进程磁盘读
例如:rate(namedprocess_namegroup_read_bytes_total{groupname=~".*prometheus.*"}[2m])
namedprocess_namegroup_write_bytes_total,进程磁盘写
rate(namedprocess_namegroup_write_bytes_total{groupname=~".*prometheus.*"}[2m])
最后以进程数查询结果如下图所示:
使用Grafana展示效果
,
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com