Telegraf: How to extract from fields using regex processor?

王林
Release: 2024-02-10 12:15:07
forward
836 people have browsed it

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.
Copy after login

使用此配置,结果键“上游”是初始消息的副本,但不包含“正则表达式”内容的一部分。

[[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"
Copy after login

当前输出:

2022/11/17 10:38:48 In the last 1h0m0s, there were 1 connections. Traffic 3 MB ↓ 5 MB.
Copy after login

如何获得小数点?

我对如何在这里使用正则表达式感到相当困惑,因为在网络上的几个示例中它应该像这样工作。例如,请参阅: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"
Copy after login

获取:

upstream="60 MB"
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!