Process-exporter
Process-exporter 主要监控主机进程状态,采集服务的进程数、消耗CPU、内存、IO资源等。
Process-exporter 官网
https://github.com/ncabatoff/process-exporter
添加prometheus用户
添加prometheus用户
groupadd prometheus
useradd -g prometheus -s /sbin/nologin prometheus
二进制部署Process-exporter
1,下载Process-exporter
wget https://github.com/ncabatoff/process-exporter/releases/download/v0.7.10/process-exporter-0.7.10.linux-amd64.tar.gz
tar -xvf process-exporter-0.7.10.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv process-exporter-0.7.10.linux-amd64/ process-exporter
2,process-exporter 版本信息
/usr/local/process-exporter/process-exporter --version
3,运行process-exporter
./process-exporter -config.path process-name.yaml >process.log 2>&1 &
4,systemctl 管理process-exporter
vim /usr/lib/systemd/system/process-exporter.service
[Unit]
Description=process-exporter
After=network.target
[Service]
User=root
Type=simple
ExecStart=/usr/local/process-exporter/process-exporter --config.path=/usr/local/process-exporter/process-name.yaml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
5,启动、开机启动process-exporter
systemctl start process-exporter && systemctl enable process-exporter
ps -ef |grep process-exporter
6,Process-exporter 配置文件
默认无配置文件需要手动创建
vim process-name.yaml
process_names:
- name: "{{.Matches}}"
cmdline:
- 'prometheus'
- name: "{{.Matches}}"
cmdline:
- 'chronyd'
{{.Matches}}模板表示映射包含应用命令行所产生的所有匹配项
7,process exporter 模板变量
8,process exporter 常用指标
运行的进程数
namedprocess_namegroup_num_procs
Running/Sleeping/Other/Zombie状态的进程数
namedprocess_namegroup_states
获取/proc/[pid]/stat 进程CPU utime、stime状态时间
namedprocess_namegroup_cpu_seconds_total
获取/proc/[pid]/io 进程读取字节数
namedprocess_namegroup_read_bytes_total
获取/proc/[pid]/io 进程写入字节数
namedprocess_namegroup_write_bytes_total
获取进程使用的内存字节数
namedprocess_namegroup_memory_bytes
获取进程使用的文件描述符数量
namedprocess_namegroup_open_filedesc
运行的线程数
namedprocess_namegroup_thread_count
获取线程CPU状态时间
namedprocess_namegroup_thread_cpu_seconds_total
获取线程IO字节数
namedprocess_namegroup_thread_io_bytes_total
9,http 访问测试(process-exporter默认监听9256端口)
process-exporter默认端口9256下
curl http://localhost:9256/metrics
Prometheus process-exporter 配置
1,prometheus.yml中加入process-exporter
vim /usr/local/prometheus/prometheus.yml
- job_name: 'process'
static_configs:
- targets: ['192.168.100.167:9256']
2,检查prometheus.yml格式
/usr/local/prometheus/promtool check config /usr/local/prometheus/prometheus.yml
3,Prometheus restful接口热加载配置
curl -X POST http://127.0.0.1:9090/-/reload
访问 Prometheus Web UI 查询数据
查询服务进程数
namedprocess_namegroup_num_procs
Prometheus Rule 告警规则
1,创建rule告警目录
mkdir -p /usr/local/prometheus/rules/
chown prometheus.prometheus /usr/local/prometheus/rules/
2,编辑rule配置文件
vim /usr/local/prometheus/rules/rules.yml
- name: process_status
rules:
- alert: process_status
expr: namedprocess_namegroup_num_procs==0
for: 1m
labels:
severity: critical
annotations:
summary: "主机 {{ $labels.instance }} process 异常!!!"
description: "{{ $labels.instance }} {{$labels.groupname}} process异常!!!(value: {{ $value }})"
3,检查rule文件格式
/usr/local/prometheus/promtool check rules rules.yml
Prometheus 告警测试
1,停止主机 192.168.100.234 chronyd服务
systemctl stop chronyd
2,访问 Prometheus Web UI 查看Alerts