procstat采集插件 您所在的位置:网站首页 destoon80采集插件 procstat采集插件

procstat采集插件

2024-07-13 20:38| 来源: 网络整理| 查看: 265

procstat采集插件

进程监控插件,两个核心作用,监控进程是否存活、监控进程使用了多少资源(CPU、内存、文件句柄等)

存活监控

如果进程监听了端口,可以直接用 net_response 来做存活性监控即可。

进程筛选

机器上进程很多,我们要做进程监控,就要想办法告诉 Categraf 要监控哪些进程,通过 search 打头的那几个配置,可以做进程过滤筛选:

# [[instances]] 这一行默认是注释的,需要打开注释 [[instances]] # # executable name (ie, pgrep ) search_exec_substring = "nginx" # # pattern as argument for pgrep (ie, pgrep -f ) # search_cmdline_substring = "n9e server" # # windows service name # search_win_service = "" search_exec_substring 相当于拿 readlink -e /proc//exe 与 search_exec_substring的内容做字符串匹配,如果匹配上了,就采集这个进程的信息 或者用注释里的方法pgrep 去匹配 search_cmdline_substring 相当于拿 cat /proc//cmdline 与 search_cmdline_substring的内容做字符串匹配,如果匹配上了,就采集这个进程的信息 或者用注释里的方法 pgrep -f 去匹配 search_win_service 用于 windows 机器,表示要监控的 windows 服务名字, 当然windows 机器上也可以用 search_exec_substring 或者 search_cmdline_substring 来做进程筛选

上面三个 search 相关的配置,每个采集目标选用其中一个。有一个额外的配置,search_user 配合search_exec_substring或者search_cmdline_substring使用,表示匹配指定username的特定进程。如果不需要指定username ,保持配置注释即可。

# # search process with specific user, option with exec_substring or cmdline_substring # search_user = "" mode

mode 配置有两个值供选择,一个是 solaris,一个是 irix,默认是 irix,用这个配置来决定使用哪种 cpu 使用率的计算方法:

func (ins *Instance) gatherCPU(slist *types.SampleList, procs map[PID]Process, tags map[string]string, solarisMode bool) { var value float64 for pid := range procs { v, err := procs[pid].Percent(time.Duration(0)) if err == nil { if solarisMode { value += v / float64(runtime.NumCPU()) slist.PushFront(types.NewSample("cpu_usage", v/float64(runtime.NumCPU()), map[string]string{"pid": fmt.Sprint(pid)}, tags)) } else { value += v slist.PushFront(types.NewSample("cpu_usage", v, map[string]string{"pid": fmt.Sprint(pid)}, tags)) } } } if ins.GatherTotal { slist.PushFront(types.NewSample("cpu_usage_total", value, tags)) } } gather_total

比如进程名字是 mysql 的进程,同时可能运行了多个,我们想知道这个机器上的所有 mysql 的进程占用的总的 cpu、mem、fd 等,就设置 gather_total = true,当然,对于 uptime 和 limit 的采集,gather_total 的时候是取的多个进程的最小值

gather_per_pid

还是拿 mysql 举例,一个机器上可能同时运行了多个,我们可能想知道每个 mysql 进程的资源占用情况,此时就要启用 gather_per_pid 的配置,设置为 true,此时会采集每个进程的资源占用情况,并附上 pid 作为标签来区分

gather_md5

计算二进制文件的md5(binary_md5sum)以及cmdline的md5(cmdline_md5sum), 每个采集周期计算一次。因为涉及磁盘IO,可能会带来额外的资源开销,比如消耗更多cpu和IO资源,v0.3.61-v0.3.72版本默认开启,v0.3.73及以上版本默认是关闭。

gather_more_metrics

默认 procstat 插件只是采集进程数量,如果想采集进程占用的资源,就要启用 gather_more_metrics 中的项,启用哪个就额外采集哪个

一个windows下的特殊场景

如果windows下是通过脚本启动了多个进程, tasklist -v 看起来都是cmd.exe, 这时可以设置任意一个 gather_more_metrics ,比如 uptime

gather_more_metrics = [ "uptime", ]

这时采集的指标会多一个 window_title=xxxx的label,其中xxx就是进程窗口的标题,可以用来区分不同的进程。这个场景下要求categraf不能以服务运行,可以使用 scripts/win_run.bat start 和 scripts/win_run.bat stop 来启动和停止categraf。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有