菜单
开源

发现进程

查找.process用于在本地Linux OS上发现运行中的进程。

注意

要使用查找.process组件,您必须以root权限运行Alloy并在host PID命名空间内。

用法

alloy
discovery.process "LABEL" {

}

参数

以下参数被支持

名称类型描述默认必需
joinlist(map(string))Join external targets to discovered processes targets based on __container_id__ label.no
refresh_intervaldurationHow often to sync targets.“60s”no

Targets joining

If join is specified, 查找.process will join the discovered processes based on the __container_id__ label.

例如,如果join指定如下:

json
[
  {
    "pod": "pod-1",
    "__container_id__": "container-1"
  },
  {
    "pod": "pod-2",
    "__container_id__": "container-2"
  }
]

并且发现的进程是:

json
[
  {
    "__process_pid__": "1",
    "__container_id__": "container-1"
  },
  {
    "__process_pid__": "2"
  }
]

生成的目标是

json
[
  {
    "__container_id__": "container-1",
    "__process_pid__": "1",
    "pod": "pod-1"
  },
  {
    "__process_pid__": "2"
  },
  {
    "__container_id__": "container-1",
    "pod": "pod-1"
  },
  {
    "__container_id__": "container-2",
    "pod": "pod-2"
  }
]

查找.process定义内部支持以下块:

层次结构描述必需
discover_configdiscover_configConfigure which process metadata to discover.no

discover_config block

The discover_config block describes which process metadata to discover.

以下参数被支持

名称类型描述默认必需
exeboolA flag to enable discovering __meta_process_exe label.trueno
cwdboolA flag to enable discovering __meta_process_cwd label.trueno
commandlineboolA flag to enable discovering __meta_process_commandline label.trueno
uidboolA flag to enable discovering __meta_process_uid: label.trueno
usernameboolA flag to enable discovering __meta_process_username: label.trueno
container_idboolA flag to enable discovering __container_id__ label.trueno

导出字段

The following fields are exported and can be referenced by other components

名称类型描述
targetslist(map(string))The set of processes discovered on the local Linux OS.

每个目标包含以下标签

  • __process_pid__: The process PID.
  • __meta_process_exe:进程可执行文件路径。从/proc/<pid>/exe获取。
  • __meta_process_cwd:进程当前工作目录。从/proc/<pid>/cwd获取。
  • __meta_process_commandline:进程命令行。从/proc/<pid>/cmdline获取。
  • __meta_process_uid:进程UID。从/proc/<pid>/status获取。
  • __meta_process_username:进程用户名。从__meta_process_uidos/user/LookupID获取。
  • __container_id__:容器ID。从/proc/<pid>/cgroup获取。如果进程未在容器中运行,则此标签未设置。

组件健康

discovery.process仅在提供无效配置时报告为不健康。在这种情况下,导出的字段将保持其最后健康的值。

调试信息

discovery.process不暴露任何特定组件的调试信息。

调试指标

discovery.process不暴露任何特定组件的调试指标。

示例

示例在本地主机上发现进程

alloy
discovery.process "all" {
  refresh_interval = "60s"
  discover_config {
    cwd = true
    exe = true
    commandline = true
    username = true
    uid = true
    container_id = true
  }
}

示例在本地主机上发现进程并与discovery.kubernetes连接

alloy
discovery.kubernetes "pyroscope_kubernetes" {
  selectors {
    field = "spec.nodeName=" + env("HOSTNAME")
    role = "pod"
  }
  role = "pod"
}

discovery.process "all" {
  join = discovery.kubernetes.pyroscope_kubernetes.targets
  refresh_interval = "60s"
  discover_config {
    cwd = true
    exe = true
    commandline = true
    username = true
    uid = true
    container_id = true
  }
}

兼容组件

discovery.process可以接受以下组件的参数

discovery.process的导出可以被以下组件消费

注意

连接某些组件可能没有意义,或者组件可能需要进一步配置才能正确连接。有关更多详细信息,请参阅链接文档。