合并 promtail 配置中两个标签的值
如何在 promtail 配置中添加多个标签的值并将它们分配给另一个标签?
scrape_configs:
- job_name: journal
journal:
max_age: 12h
relabel_configs:
- source_labels: ['__journal__machine_id']
target_label: 'HostId'
- source_labels: ['__journal__hostname']
target_label: 'HostName'
- source_labels: ['__journal_syslog_identifier']
target_label: 'ApplicationName'
pipeline_stages:
- match:
selector: '{ApplicationName="test-app"}'
stages:
- static_labels:
OriginId: //here I want to asign HostId+HostName+ApplicationName
最后,我预计标签 OriginId 的值为 HostId+HostName+ApplicationName
How to add the values of multiple labels and assign them to another label in promtail config?
scrape_configs:
- job_name: journal
journal:
max_age: 12h
relabel_configs:
- source_labels: ['__journal__machine_id']
target_label: 'HostId'
- source_labels: ['__journal__hostname']
target_label: 'HostName'
- source_labels: ['__journal_syslog_identifier']
target_label: 'ApplicationName'
pipeline_stages:
- match:
selector: '{ApplicationName="test-app"}'
stages:
- static_labels:
OriginId: //here I want to asign HostId+HostName+ApplicationName
In the end, I expect the value of label OriginId would be HostId+HostName+ApplicationName
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
static_labels
只允许向标签集中添加静态标签,即不能使用其他标签的值。由于您已经有了relabel_configs
部分,也许您可以直接从重新标记步骤生成OriginId
?类似于:在这种情况下,如果输入标签集如下所示:
OriginId
最终的值为:machine-id-1_host1_abcde-123
。默认分隔符
(如果配置中未指定分隔符,则为;
)。static_labels
only allows adding a static label to the label set, i.e you cannot use the value of other labels. Since you already have arelabel_configs
section maybe you can generate theOriginId
directly from the relabeling step? Something like:In this case if the input label set looks like:
OriginId
would end up with the value:machine-id-1_host1_abcde-123
. The defaultseparator
(if none is specified in the configuration is;
).您可以在
relabel_config
中使用带有separator
的replace
操作。这是一个例子:
我认为这应该适合你。
You can use the
replace
action with aseparator
in arelabel_config
.Here's an example:
I think that should work for you.
这可以通过模板阶段来实现。
下面的示例从 filename 映射
team
和space
以创建一个名为namespace
的新标签。This can be achieved via template stage.
Below example maps
team
andspace
from filename to create a new label callednamespace
.