Process-exporter 主要是对进程进行监控。

安装使用

安装

wget https://github.com/ncabatoff/process-exporter/releases/download/v0.4.0/process-exporter-0.4.0.linux-amd64.tar.gz 
tar -xvf process-exporter-0.4.0.linux-amd64.tar.gz -C /usr/local/

配置

选择要监视的进程并将它的分组,提供命令行参数或者使用YAML配置文件两种方法。

整体模版

process_names:
  - matcher1
  - matcher2
  ...
  - matcherN
  • 默认定义全部进程监控

    vim conf.yaml
    process_names:
      - name: "{{.Comm}}"
        cmdline:
        - '.+'
    
  • name 进程名,可以使用变量模版匹配

  • 模版变量

    可用的模板变量:

    {{.Comm}} 包含原始可执行文件的basename,换句话说 在/proc/<pid>/stat
    {{.ExeBase}} 包含可执行文件的basename,这个是name的默认值
    {{.ExeFull}} 包含可执行文件的完全限定路径
    {{.Username}} contains the username of the effective user
    {{.Matches}} 映射包含应用命令行所产生的所有匹配项
    
  • 创建配置文件定义进程名监控

    Process-exporter 可以进程名字匹配进程,获取进程信息。匹配规则由name对应的模板变量决定,以下表示监控进程名字为nginx 与 zombie 的进程状态

    vim process-name.yaml
    process_names:
      - name: "{{.Matches}}"
        cmdline:
        - 'nginx'
    
      - name: "{{.Matches}}"
        cmdline:
        - 'zombie'
    
  • 进程选择器(process selectors)

    process_names 中的每个项必须包含一个或者多个选择器(comm,exe –OR或者 cmdline–AND) ;如果存在多个选择器,则它们都必须匹配

启动服务

./process-exporter -config.path process-name.yaml &

查看数据

curl http://localhost:9256/metrics

监控项

常用进程监控项

  • 总进程数

    sum(namedprocess_namegroup_states)
    
  • 总僵尸进程数

    sum(namedprocess_namegroup_states{state="Zombie"})
    

    namedprocess_namegroup_都是以这个开头的

  • num_procs:Number of processes in this group

  • cpu_seconds_total:CPU usage,类似于node_cpu_seconds_total

  • read_bytes_total:io read

  • write_bytes_total:io write

  • major_page_faults_total:Number of major page faults based on /proc/[pid]/stat

  • minor_page_faults_total:Number of minor page faults based on /proc/[pid]/stat

  • context_switches_total:voluntary_ctxt_switches

  • memory_bytes:memory used

  • open_filedesc:Number of file descriptors,基于/proc/[pid]/fd

  • worst_fd_ratio:fd limit

  • oldest_start_time_seconds:the oldest process in the group started

  • num_threads:Sum of number of threads of all process in the group

  • states:Running, Sleeping, Waiting, Zombie, Other:Number of threads in the group

还有线程的一些指标,默认关闭,需要开启

原理

读取/proc/[pid]/(stat,fd)等文件的数据进行解析来获取进程的相关状态和资源情况。