prometheus+process_exporter监控进程

简介

Prometheus有众多的Exporter可供使用,如在Prometheus+Grafana监控系统搭建一文中提到的Node Exporter就可以用来采集机器的各项指标,从而监控机器的状态。

如果机器上运行了一些小脚本,想要对其进行监控但又不想用上一些在代码里做信息采集的SDK那么重,比如只是单纯想要监控该脚本是否一直在运行,那么Process-Exporter会是一个现成的好选择。

安装process-exporter

安装好了Prometheus的前提下,在被监控机器安装process-exporter

1
2
3
4
5
6
7
8
9
10
wget https://github.com/ncabatoff/process-exporter/releases/download/v0.5.0/process-exporter-0.5.0.linux-amd64.tar.gz
tar xf process-exporter-0.5.0.linux-amd64.tar.gz
cd process-exporter-0.5.0.linux-amd64
# 创建配置文件
vim process-name.yaml

process_names:
- name: "{{.Matches}}"
cmdline:
- '.+'

这里,在配置文件(process-name.yaml)中,我们添加了监控所有进程,一个process_names就定义了要监控的一组进程,{ {.Matches} }模板表示映射包含应用命令行所产生的所有匹配项,还有其他模板如下:

模板变量:

1
2
3
4
5
{ {.Comm} } 包含原始可执行文件的基本名称,即第二个字段 /proc//stat
{ {.ExeBase} } 包含可执行文件的基名
{ {.ExeFull} } 包含可执行文件的完全限定路径
{ {.Username} } 包含有效用户的用户名
{ {.Matches} } map包含应用cmdline regexps产生的所有匹配项
1
2
3
4
# 配置后启动
nohup ./process-exporter -config.path process-name.yaml &
# 测试
curl http://192.168.1.72:9256/metrics

prometheus服务器添加数据源

修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'

# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.

static_configs:
- targets: ['localhost:9090']

# 新增被监控服务器
- job_name: 'process'
static_configs:
- targets: ['192.168.1.72:9256']

控制台查看

没问题后添加到grafana-url为prometheus的地址+端口




注:使用process-exporter的时候需要加上node_exporter一块使用,node_exporter作为pull数据的组件

  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2019-2023 XIN LONG
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信