Home >Backend Development >Golang >Telegraf: How to extract from fields using regex processor?
php小编香蕉在本文中将介绍如何使用Telegraf的正则表达式处理器从字段中提取信息。Telegraf是一个功能强大的开源数据收集器,可以将各种数据源的信息收集并发送到不同的目的地。正则表达式处理器是Telegraf中的一种插件,它可以帮助我们从原始数据中提取特定的字段。本文将详细介绍如何使用正则表达式处理器,并提供一些实用的示例和技巧,以帮助读者更好地掌握这一功能。
我想使用 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"
The above is the detailed content of Telegraf: How to extract from fields using regex processor?. For more information, please follow other related articles on the PHP Chinese website!