discovery.process
discovery.process
发现本地 Linux 操作系统上运行的进程。
注意
要使用
discovery.process
组件,您必须以 root 身份并在主机 PID 命名空间内运行 Alloy。
用法
discovery.process "<LABEL>" {
}
参数
您可以将以下参数与 discovery.process
一起使用
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
join | list(map(string)) | 基于 __container_id__ 标签将外部目标加入到发现的进程目标。 | 否 | |
refresh_interval | duration | 同步目标的频率。 | “60 秒” | 否 |
目标加入
如果您指定 join
,discovery.process
将基于 __container_id__
标签加入发现的进程。
例如,如果 join
指定如下
[
{
"pod": "pod-1",
"__container_id__": "container-1"
},
{
"pod": "pod-2",
"__container_id__": "container-2"
}
]
并且发现的进程是
[
{
"__process_pid__": "1",
"__container_id__": "container-1"
},
{
"__process_pid__": "2"
}
]
结果目标是
[
{
"__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"
}
]
块
您可以将以下块与 discovery.process
一起使用
块 | 描述 | 必需 |
---|---|---|
discover_config | 配置要发现的进程元数据。 | 否 |
discover_config
discover_config
块描述了要发现的进程元数据。
支持以下参数
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
exe | bool | 一个标志,用于启用发现 __meta_process_exe 标签。 | true | 否 |
cwd | bool | 一个标志,用于启用发现 __meta_process_cwd 标签。 | true | 否 |
commandline | bool | 一个标志,用于启用发现 __meta_process_commandline 标签。 | true | 否 |
uid | bool | 一个标志,用于启用发现 __meta_process_uid : 标签。 | true | 否 |
username | bool | 一个标志,用于启用发现 __meta_process_username : 标签。 | true | 否 |
cgroup_path | bool | 一个标志,用于启用发现 __meta_cgroup_path__ 标签。 | false | 否 |
container_id | bool | 一个标志,用于启用发现 __container_id__ 标签。 | true | 否 |
导出的字段
以下字段已导出,可以被其他组件引用
名称 | 类型 | 描述 |
---|---|---|
targets | list(map(string)) | 在本地 Linux 操作系统上发现的进程集。 |
每个目标都包含以下标签
__container_id__
: 容器 ID。从/proc/<pid>/cgroup
获取。如果进程未在容器中运行,则不设置此标签。__meta_cgroup_path
: 进程在其下运行的 cgroup 路径。在 cgroups v1 的情况下,此标签包括所有由|
分隔的控制器路径。__meta_process_commandline
: 进程命令行。从/proc/<pid>/cmdline
获取。__meta_process_cwd
: 进程当前工作目录。从/proc/<pid>/cwd
获取。__meta_process_exe
: 进程可执行文件路径。从/proc/<pid>/exe
获取。__meta_process_uid
: 进程 UID。从/proc/<pid>/status
获取。__meta_process_username
: 进程用户名。从__meta_process_uid
和os/user/LookupID
获取。__process_pid__
: 进程 PID。
组件健康状况
仅当 discovery.process
被赋予无效配置时,才报告为不健康。在这些情况下,导出的字段保留其最后一次健康值。
调试信息
discovery.process
不公开任何组件特定的调试信息。
调试指标
discovery.process
不公开任何组件特定的调试指标。
示例
在本地主机上发现进程的示例
discovery.process "all" {
refresh_interval = "60s"
discover_config {
cwd = true
exe = true
commandline = true
username = true
uid = true
cgroup_path = true
container_id = true
}
}
在本地主机上发现进程并与 discovery.kubernetes
连接的示例
discovery.kubernetes "pyroscope_kubernetes" {
selectors {
field = "spec.nodeName=" + sys.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
}
}
基于 cgroups
路径在本地主机上发现进程的示例
以下示例配置演示了如何在本地主机上发现 systemd 服务下运行的进程。
discovery.process "all" {
refresh_interval = "60s"
discover_config {
cwd = true
exe = true
commandline = true
username = true
uid = true
cgroup_path = true
container_id = true
}
}
discovery.relabel "systemd_services" {
targets = discovery.process.all.targets
// Only keep the targets that correspond to systemd services
rule {
action = "keep"
regex = "^.*/([a-zA-Z0-9-_]+).service(?:.*$)"
source_labels = ["__meta_cgroup_id"]
}
}
兼容组件
discovery.process
可以接受来自以下组件的参数
- 导出 目标 的组件
discovery.process
具有可以被以下组件使用的导出
- 使用 目标 的组件
注意
连接某些组件可能不合理,或者组件可能需要进一步配置才能使连接正常工作。有关更多详细信息,请参阅链接的文档。