带有正则表达式的标签-普罗米修斯 [英] label with regex- Prometheus

查看:75
本文介绍了带有正则表达式的标签-普罗米修斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用正则表达式添加新标签.名称实例是 pr-na01-na02-A我试图只获得 pr-na01,所以我这样做了:

I'm trying to add a new label with regex. the name instance is pr-na01-na02-A I'm trying to get only the pr-na01, so I did this:

  - source_labels: ['__meta_ec2_tag_Name']
    regex: '^[^-]*-[^-]*'
    target_label: 'test'
    replacement: '$1'

在 Prometheus 指标下仍然看不到新标签(测试).

and still don't see a new label (test) under Prometheus metrics.

推荐答案

问题是您没有捕获组,所以 $1 为空.你也没有匹配完整的字符串.

The issue is that you have no capture groups, so $1 is empty. Also you're not matching the full string.

试试 (^[^-]*-[^-]*).* 作为正则表达式.

Try (^[^-]*-[^-]*).* as the regex.

这篇关于带有正则表达式的标签-普罗米修斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆