常用动作
| action | 作用 | 典型用例 |
|---|---|---|
| keep / drop | 保留或丢弃目标 | 只采集特定角色实例 |
| replace | 用正则捕获改写标签 | 从 __address__ 提取端口生成标签 |
| labeldrop / labelkeep | 删或保留标签 | 清理无用的元标签 |
| hashmod | 按哈希分片 | 多个 Prometheus 分担大目标集 |
从地址提取实例标签并改写抓取端口
从地址提取实例标签并改写抓取端口
relabel_configs:
- source_labels: [__address__]
regex: '([^:]+):(\\d+)'
target_label: instance
replacement: '$1'
- source_labels: [__address__]
regex: '([^:]+):.*'
target_label: __address__
replacement: '$1:9100'以 __ 开头的内置标签只在抓取前阶段有效:__param_*、__scheme__ 等都是 relabel 可改写的对象。