我想使用 telegraf 正则表达式处理器插件从此输入中提取连接、上游和下游的值:
2022/11/16 22:38:48 in the last 1h0m0s, there were 10 connections. traffic relayed ↑ 60 mb, ↓ 4 mb.
使用此配置,结果键“上游”是初始消息的副本,但不包含“正则表达式”内容的一部分。
[[processors.regex]] tagpass = ["snowflake-proxy"] [[processors.regex.fields]] ## field to change key = "message" ## all the power of the go regular expressions available here ## for example, named subgroups pattern = 'relayed.{3}(?p<upstream>d{1,4}w.b),' replacement = "${upstream}" ## if result_key is present, a new field will be created ## instead of changing existing field result_key = "upstream"
当前输出:
2022/11/17 10:38:48 In the last 1h0m0s, there were 1 connections. Traffic 3 MB ↓ 5 MB.
如何获得小数点?
我对如何在这里使用正则表达式感到相当困惑,因为在网络上的几个示例中它应该像这样工作。例如,请参阅:http://wiki.webperfect.ch/index.php?title=telegraf:_processor_plugins
替换配置选项指定您要替换任何匹配项的内容。
我认为你想要更接近这个的东西:
[[processors.regex.fields]] key = "message" pattern = '.*relayed.{3}(?p<upstream>d{1,4}w.b),.*$' replacement = "${1}" result_key = "upstream"
获取:
upstream="60 MB"