文档文档

Procstat 输入插件

此插件允许监控一个或多个进程的系统资源使用情况。该插件提供有关单个进程的指标以及关于搜索返回的 PID 数量的累积指标。可以通过例如命令的正则表达式、拥有进程的用户或启动进程的服务来过滤进程。

引入于: Telegraf v0.2.0 标签: system 操作系统支持: all

全局配置选项

插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md

配置

# Monitor process cpu and memory usage
[[inputs.procstat]]
  ## PID file to monitor process
  pid_file = "/var/run/nginx.pid"
  ## executable name (ie, pgrep <exe>)
  # exe = "nginx"
  ## pattern as argument for pgrep (ie, pgrep -f <pattern>)
  # pattern = "nginx"
  ## user as argument for pgrep (ie, pgrep -u <user>)
  # user = "nginx"
  ## Systemd unit name, supports globs when include_systemd_children is set to true
  # systemd_unit = "nginx.service"
  # include_systemd_children = false
  ## CGroup name or path, supports globs
  # cgroup = "systemd/system.slice/nginx.service"
  ## Supervisor service names of hypervisorctl management
  # supervisor_units = ["webserver", "proxy"]

  ## Windows service name
  # win_service = ""

  ## override for process_name
  ## This is optional; default is sourced from /proc/<pid>/status
  # process_name = "bar"

  ## Field name prefix
  # prefix = ""

  ## Mode to use when calculating CPU usage. Can be one of 'solaris' or 'irix'.
  # mode = "irix"

  ## Add the given information tag instead of a field
  ## This allows to create unique metrics/series when collecting processes with
  ## otherwise identical tags. However, please be careful as this can easily
  ## result in a large number of series, especially with short-lived processes,
  ## creating high cardinality at the output.
  ## Available options are:
  ##   cmdline   -- full commandline
  ##   pid       -- ID of the process
  ##   ppid      -- ID of the process' parent
  ##   status    -- state of the process
  ##   user      -- username owning the process
  ## socket only options:
  ##   protocol  -- protocol type of the process socket
  ##   state     -- state of the process socket
  ##   src       -- source address of the process socket (non-unix sockets)
  ##   src_port  -- source port of the process socket (non-unix sockets)
  ##   dest      -- destination address of the process socket (non-unix sockets)
  ##   dest_port -- destination port of the process socket (non-unix sockets)
  ##   name      -- name of the process socket (unix sockets only)
  ## Available for procstat_lookup:
  ##   level     -- level of the process filtering
  # tag_with = []

  ## Properties to collect
  ## Available options are
  ##   cpu     -- CPU usage statistics
  ##   limits  -- set resource limits
  ##   memory  -- memory usage statistics
  ##   mmap    -- mapped memory usage statistics (caution: can cause high load)
  ##   sockets -- socket statistics for protocols in 'socket_protocols'
  # properties = ["cpu", "limits", "memory", "mmap"]

  ## Protocol filter for the sockets property
  ## Available options are
  ##   all  -- all of the protocols below
  ##   tcp4 -- TCP socket statistics for IPv4
  ##   tcp6 -- TCP socket statistics for IPv6
  ##   udp4 -- UDP socket statistics for IPv4
  ##   udp6 -- UDP socket statistics for IPv6
  ##   unix -- Unix socket statistics
  # socket_protocols = ["all"]

  ## Method to use when finding process IDs.  Can be one of 'pgrep', or
  ## 'native'.  The pgrep finder calls the pgrep executable in the PATH while
  ## the native finder performs the search directly in a manor dependent on the
  ## platform.  Default is 'pgrep'
  # pid_finder = "pgrep"

  ## New-style filtering configuration (multiple filter sections are allowed)
  # [[inputs.procstat.filter]]
  #    ## Name of the filter added as 'filter' tag
  #    name = "shell"
  #
  #    ## Service filters, only one is allowed
  #    ## Systemd unit names (wildcards are supported)
  #    # systemd_units = []
  #    ## CGroup name or path (wildcards are supported)
  #    # cgroups = []
  #    ## Supervisor service names of hypervisorctl management
  #    # supervisor_units = []
  #    ## Windows service names
  #    # win_service = []
  #
  #    ## Process filters, multiple are allowed
  #    ## Regular expressions to use for matching against the full command
  #    # patterns = ['.*']
  #    ## List of users owning the process (wildcards are supported)
  #    # users = ['*']
  #    ## List of executable paths of the process (wildcards are supported)
  #    # executables = ['*']
  #    ## List of process names (wildcards are supported)
  #    # process_names = ['*']
  #    ## Recursion depth for determining children of the matched processes
  #    ## A negative value means all children with infinite depth
  #    # recursion_depth = 0

Windows 支持

该插件报告 Windows 上的进程信息,但如果您需要更深入的进程信息,建议使用 win_perf_counterswin_wmi 输入插件。

Darwin 特定

如果您在 Darwin 上同时使用 supervisor_unitspattern,则 **必须** 使用 pgrep 查找器,因为底层库依赖于 pgrep

权限

某些文件或目录可能需要提升的权限。因此,用户可能需要授予 telegraf 更高级别的权限才能访问并生成指标。

Posix 系统上的远程用户

要解析由远程用户(例如 LDAP 或 NIS)拥有的进程的用户名,插件依赖于 id 命令。该命令必须在系统中可用,位于 PATH 中,并且 Telegraf 可以执行它,否则将无法解析用户名,而是使用用户 ID。

Metrics

有关这些标签和字段的说明,请参考以下内容之一

下面是一组示例标签和字段

  • procstat
    • 标签 (tags)
      • pid (如果请求)
      • cmdline (如果请求)
      • process_name
      • pidfile (定义时)
      • exe (定义时)
      • pattern (定义时)
      • user (选择时)
      • systemd_unit (定义时)
      • cgroup (定义时)
      • cgroup_full (当 cgroup 或 systemd_unit 与 glob 一起使用时)
      • supervisor_unit (定义时)
      • win_service (定义时)
      • parent_pid (子进程)
      • child_level (子进程)
    • 字段 (fields)
      • child_major_faults (int)
      • child_minor_faults (int)
      • created_at (int) [epoch in 纳秒]
      • cpu_time (int)
      • cpu_time_iowait (float) (除 Linux 外所有操作系统均为零)
      • cpu_time_system (float)
      • cpu_time_user (float)
      • cpu_usage (float)
      • disk_read_bytes (int, 仅限 Linux, telegraf 可能需要以 root 身份运行)
      • disk_write_bytes (int, 仅限 Linux, telegraf 可能需要以 root 身份运行)
      • involuntary_context_switches (int)
      • major_faults (int)
      • memory_anonymous (int)
      • memory_private_clean (int)
      • memory_private_dirty (int)
      • memory_pss (int)
      • memory_referenced (int)
      • memory_rss (int)
      • memory_shared_clean (int)
      • memory_shared_dirty (int)
      • memory_size (int)
      • memory_swap (int)
      • memory_usage (float)
      • memory_vms (int)
      • minor_faults (int)
      • nice_priority (int)
      • num_fds (int, telegraf 可能需要以 root 身份运行)
      • num_threads (int)
      • pid (int)
      • ppid (int)
      • status (string)
      • read_bytes (int, telegraf 可能需要以 root 身份运行)
      • read_count (int, telegraf 可能需要以 root 身份运行)
      • realtime_priority (int)
      • rlimit_cpu_time_hard (int)
      • rlimit_cpu_time_soft (int)
      • rlimit_file_locks_hard (int)
      • rlimit_file_locks_soft (int)
      • rlimit_memory_data_hard (int)
      • rlimit_memory_data_soft (int)
      • rlimit_memory_locked_hard (int)
      • rlimit_memory_locked_soft (int)
      • rlimit_memory_rss_hard (int)
      • rlimit_memory_rss_soft (int)
      • rlimit_memory_stack_hard (int)
      • rlimit_memory_stack_soft (int)
      • rlimit_memory_vms_hard (int)
      • rlimit_memory_vms_soft (int)
      • rlimit_nice_priority_hard (int)
      • rlimit_nice_priority_soft (int)
      • rlimit_num_fds_hard (int)
      • rlimit_num_fds_soft (int)
      • rlimit_realtime_priority_hard (int)
      • rlimit_realtime_priority_soft (int)
      • rlimit_signals_pending_hard (int)
      • rlimit_signals_pending_soft (int)
      • signals_pending (int)
      • voluntary_context_switches (int)
      • write_bytes (int, telegraf 可能需要以 root 身份运行)
      • write_count (int, telegraf 可能需要以 root 身份运行)
  • procstat_lookup
    • 标签 (tags)
      • exe
      • pid_finder
      • pid_file
      • pattern
      • prefix
      • user
      • systemd_unit
      • cgroup
      • supervisor_unit
      • win_service
      • result
    • 字段 (fields)
      • pid_count (int)
      • running (int)
      • result_code (int, success = 0, lookup_error = 1)
  • procstat_socket (如果配置,仅限 Linux)
    • 标签 (tags)
      • pid (如果请求)
      • protocol (如果请求)
      • cmdline (如果请求)
      • process_name
      • pidfile (定义时)
      • exe (定义时)
      • pattern (定义时)
      • user (选择时)
      • systemd_unit (定义时)
      • cgroup (定义时)
      • cgroup_full (当 cgroup 或 systemd_unit 与 glob 一起使用时)
      • supervisor_unit (定义时)
      • win_service (定义时)
    • 字段 (fields)
      • protocol
      • state
      • pid
      • src
      • src_port (仅限 tcp 和 udp 套接字)
      • dest (仅限 tcp 和 udp 套接字)
      • dest_port (仅限 tcp 和 udp 套接字)
      • bytes_received (仅限 tcp 套接字)
      • bytes_sent (仅限 tcp 套接字)
      • lost (仅限 tcp 套接字)
      • retransmits (仅限 tcp 套接字)
      • rx_queue
      • tx_queue
      • inode (仅限 unix 套接字)

注意:资源限制 > 2147483647 将报告为 2147483647。

示例输出

procstat_lookup,host=prash-laptop,pattern=influxd,pid_finder=pgrep,result=success pid_count=1i,running=1i,result_code=0i 1582089700000000000
procstat,host=prash-laptop,pattern=influxd,process_name=influxd,user=root involuntary_context_switches=151496i,child_minor_faults=1061i,child_major_faults=8i,cpu_time_user=2564.81,pid=32025i,major_faults=8609i,created_at=1580107536000000000i,voluntary_context_switches=1058996i,cpu_time_system=616.98,memory_swap=0i,memory_locked=0i,memory_usage=1.7797634601593018,num_threads=18i,cpu_time_iowait=0,memory_rss=148643840i,memory_vms=1435688960i,memory_data=0i,memory_stack=0i,minor_faults=1856550i 1582089700000000000
procstat_socket,host=prash-laptop,process_name=browser,protocol=tcp4 bytes_received=826987i,bytes_sent=32869i,dest="192.168.0.2",dest_port=443i,lost=0i,pid=32025i,retransmits=0i,rx_queue=0i,src="192.168.0.1",src_port=52106i,state="established",tx_queue=0i 1582089700000000000

此页面是否有帮助?

感谢您的反馈!


InfluxDB 3.8 新特性

InfluxDB 3.8 和 InfluxDB 3 Explorer 1.6 的主要增强功能。

查看博客文章

InfluxDB 3.8 现已适用于 Core 和 Enterprise 版本,同时发布了 InfluxDB 3 Explorer UI 的 1.6 版本。本次发布着重于操作成熟度,以及如何更轻松地部署、管理和可靠地运行 InfluxDB。

更多信息,请查看

InfluxDB Docker 的 latest 标签将指向 InfluxDB 3 Core

在 **2026 年 2 月 3 日**,InfluxDB Docker 镜像的 latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。

如果使用 Docker 来安装和运行 InfluxDB,latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。例如,如果使用 Docker 运行 InfluxDB v2,请将 latest 版本标签替换为 Docker pull 命令中的特定版本标签 — 例如

docker pull influxdb:2