为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Go
慕娘9325324 2023-03-15 15:20:03
我想使用 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
查看完整描述

1 回答

?
繁星coding

TA贡献1797条经验 获得超4个赞

replacement 配置选项指定您要为任何匹配项替换的内容。


我想你想要更接近于此的东西:


  [[processors.regex.fields]]

    key = "message"

    pattern = '.*Relayed.{3}(?P<UPSTREAM>\d{1,4}\W.B),.*$'

    replacement = "${1}"

    result_key = "upstream"

要得到:


upstream="60 MB"


查看完整回答
反对 回复 2023-03-15
  • 1 回答
  • 0 关注
  • 159 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号