prometheus 监控之 进程监控(process-exporter)
http://www.github.com/ncabatoff/process-exporter
exporter下载:https://github.com/ncabatoff/process-exporter/releases/download/v0.4.0/process-exporter-0.4.0.linux-amd64.tar.gz
[xxx@trade1 ~]$ process-exporter --help
Usage of process-exporter:
-children
if a proc is tracked, track with it any children that aren't part of their own group (default true) -config.path string path to YAML config file -debug log debugging information to stdout -man print manual -namemapping string comma-seperated list, alternating process name and capturing regex to apply to cmdline -once-to-stdout-delay duration Don't bind, just wait this much time, print the metrics once to stdout, and exit
-procfs string
path to read proc data from (default "/proc")
-procnames string
comma-seperated list of process names to monitor
-recheck
recheck process names on each scrape
-web.listen-address string
Address on which to expose metrics and web interface. (default ":9256")
-web.telemetry-path string
Path under which to expose metrics. (default "/metrics")
配置
选择要监视的进程并将它的分组,提供命令行参数或者使用YAML配置文件。
为了避免与命令行YAML元素混淆,我们将 /proc//cmdline的空分隔内容引用为 array argv[] 。
process_names 中的每个项目都提供了识别和命名过程的诀窍。 可选 name 标记定义用于命名匹配进程的模板;如果没有指定,name 默认为 { {.ExeBase}} 。
可用的模板变量:
{ {.Comm}} 包含原始可执行文件的basename,/proc//stat 中的换句话说,2nd 字段
{ {.ExeBase}} 包含可执行文件的basename
{ {.ExeFull}} 包含可执行文件的完全限定路径
{ {.Matches}} 映射包含应用命令行tlb所产生的所有匹配项
process_names 中的每个项必须包含一个或者多个选择器( 。comm,exe 或者 cmdline ) ;如果存在多个选择器,则它们都必须匹配。 每个选择器都是符合进程。argv[0] 或者 cmdline的comm的一个字符串列表,用于应用于 命令行的正则表达式。
对于 comm 和 exe,字符串列表是 an,表示任何匹配任何字符串的进程都将被添加到项的组中。
对于 cmdline,regex的列表是一个,也就是说它们都必须匹配。 regexp中的任何捕获组都必须使用 ?P 选项为捕获指定名称,该名称用于填充 .Matches 。
进程只能属于一个组: 即使多个项目匹配,文件中列出的第一个也会胜出。
其他性能提示:在cmdline子句中添加exe或者comm子句,这样在执行名不匹配时避免执行 regexp 。
以下配置是监控所有的进程
[xxx@trade1 bin]$ cat config.yml
process_names:
- name: "{ {.Comm}}"
cmdline:
- '.+'
启动process-exporter:
process-exporter -config.path config.yml
[root@trade1 bin]# curl 10.100.20.143:9256/metrics |grep JSL
namedprocess_namegroup_context_switches_total{ ctxswitchtype="nonvoluntary",groupname="JSL"} 0
namedprocess_namegroup_context_switches_total{ ctxswitchtype="voluntary",groupname="JSL"} 627
namedprocess_namegroup_cpu_system_seconds_total{ groupname="JSL"} 0.020000000000000018
namedprocess_namegroup_cpu_user_seconds_total{ groupname="JSL"} 0.040000000000000036
namedprocess_namegroup_major_page_faults_total{ groupname="JSL"} 0
namedprocess_namegroup_memory_bytes{ groupname="JSL",memtype="resident"} 3.444736e+06
namedprocess_namegroup_memory_bytes{ groupname="JSL",memtype="swapped"} 0
namedprocess_namegroup_memory_bytes{ groupname="JSL",memtype="virtual"} 3.487744e+07
namedprocess_namegroup_minor_page_faults_total{ groupname="JSL"} 0
namedprocess_namegroup_num_procs{ groupname="JSL"} 1
namedprocess_namegroup_num_threads{ groupname="JSL"} 1
namedprocess_namegroup_oldest_start_time_seconds{ groupname="JSL"} 1.54755489e+09
namedprocess_namegroup_open_filedesc{ groupname="JSL"} 7
namedprocess_namegroup_read_bytes_total{ groupname="JSL"} 0
namedprocess_namegroup_states{ groupname="JSL",state="Other"} 0
namedprocess_namegroup_states{ groupname="JSL",state="Running"} 0
namedprocess_namegroup_states{ groupname="JSL",state="Sleeping"} 1
namedprocess_namegroup_states{ groupname="JSL",state="Waiting"} 0
namedprocess_namegroup_states{ groupname="JSL",state="Zombie"} 0
namedprocess_namegroup_threads_wchan{ groupname="JSL",wchan="do_msgrcv"} 1
namedprocess_namegroup_worst_fd_ratio{ groupname="JSL"} 6.8359375e-06
namedprocess_namegroup_write_bytes_total{ groupname="JSL"} 0
可以看到我的进程已经在监控状态了。
Grafana 画图
https://grafana.com/dashboards/249
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
2021-07-28 办公环境下k8s网络互通方案
2021-07-28 netstat -i和-s
2020-07-28 Eureka、Zookeeper和Consul 的区别