Telegraf:如何使用正则表达式处理器从字段中提取?

我想使用 telegraf 正则表达式处理器插件从此输入中提取连接、上游和下游的值:


2022/11/16 22:38:48 In the last 1h0m0s, there were 10 connections. Traffic Relayed ↑ 60 MB, ↓ 4 MB.

使用此配置,结果键“upstream”是初始消息的副本,但没有“regexed”内容的一部分。


[[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


慕娘9325324
浏览 160回答 1
1回答

繁星coding

replacement 配置选项指定您要为任何匹配项替换的内容。我想你想要更接近于此的东西:&nbsp; [[processors.regex.fields]]&nbsp; &nbsp; key = "message"&nbsp; &nbsp; pattern = '.*Relayed.{3}(?P<UPSTREAM>\d{1,4}\W.B),.*$'&nbsp; &nbsp; replacement = "${1}"&nbsp; &nbsp; result_key = "upstream"要得到:upstream="60 MB"
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go