简体   繁体   English

Telegraf:如何在插入 influxdb 之前收集十六进制数据并应用 function?

[英]Telegraf : How collect Hexadecimal data and apply function before insert in influxdb?

I need help reading data in hexadecimal and applying a formula to transform the data.My file parse with tail:我需要帮助以十六进制读取数据并应用公式来转换数据。我的文件用尾部解析:

2022-09-15 00:04:39 AAA99 BBB99 24 43 B2 50
2022-09-15 00:04:40 BBB99 BBB99 2C 42 F1 4B

And my configuration:还有我的配置:

[global_tags]
[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = ""
  debug = true
  quiet = false
  logtarget = "file"
  logfile = "/var/log/telegraf.log"
  hostname = ""
  omit_hostname = true
[[outputs.influxdb]]
  urls = ["http://127.0.0.1:8086"]
  database = "data_hexa"
  skip_database_creation = false
  timeout = "5s"
  username = "telegraf"
  password = "***********"
  user_agent = "telegraf"
 [[outputs.file]]
   files = ["stdout", "/tmp/metrics.out"]
 [[inputs.tail]]
    files = ["/mnt/cle/hexa*.log"]
    name_override = "hexa_log"
    from_beginning = true
    max_undelivered_lines = 10000
    character_encoding = "utf-8"
    grok_patterns = ["%{CUSTOM_LOG}"]
    grok_custom_patterns = '''
CUSTOM_LOG %{TIMESTAMP_ISO8601:timestamp:ts-"2006-01-02 15:04:05"} %{WORD:AAAinfo:tag} %{WORD:BBBinfo:tag} %{BASE16NUM:01hexa} %{BASE16NUM:02hexa} %{BASE16NUM:03hexa} %{BASE16NUM:04hexa}
'''
    data_format = "grok"
    grok_timezone = "Local"

With this configuration, the data type is "string" and I want to convert the hexadecimal value to integer (IN_01hexa) and apply a change like 01hexa_convert = ((IN_01hexa)*0.8125-4.25).Then, in my database, the type of 01hexa_convert must be float.使用此配置,数据类型为“字符串”,我想将十六进制值转换为 integer (IN_01hexa) 并应用 01hexa_convert = ((IN_01hexa)*0.8125-4.25) 之类的更改。然后,在我的数据库中,类型为01hexa_convert 必须是浮点数。

You could try this to convert a string of HEX to an integer via Telegraf's converter plugin .您可以尝试通过Telegraf 的转换器插件将 HEX 字符串转换为 integer。

Sample code could be as follows:示例代码如下:

[[processors.converter]]
    [processors.converter.fields]
         integer = ["*hexa"]

As for the match processing part, it seems that we have to do it in query phase as Telegraf doesn't have such plugin yet .至于匹配处理部分,似乎我们必须在查询阶段进行,因为 Telegraf还没有这样的插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何正确配置 Telegraf 以写入来自 MQTT 的 InfluxDB 数据 - How to properly configure telegraf to write into InfluxDB data coming from MQTT 如何调试 Telegraf 不将数据从 MQTT 发送到 influxdb 的原因 - How to debug why Telegraf is not sending data from MQTT to influxdb 如何调试 Telegraf 为什么不将数据从 Openweathermap 发送到 influxdb - How to debug why Telegraf is not sending data from Openweathermap to influxdb Telegraf 插件 - Telegraf 仅针对一个插件向 influxdb 发送数据 - Telegraf plugins - Telegraf send data to influxdb only for one plugin 如何使用 FluentD 作为 Telegraf 和 InfluxDB 之间的缓冲区 - How to use FluentD as a buffer between Telegraf and InfluxDB 如何设置telegraf statsd(Influxdb)的时间精度? - How to set the time precision of the telegraf statsd (influxdb)? 如何从 CSV 文件将数据插入 Influxdb - How to insert data into Influxdb from CSV file 使用Telegraf的涌入数据在Grafana上绘制CPU使用率% - Graphing CPU Usage % on Grafana using influxDB data from Telegraf Telegraf/Influxdb URL 问题 - Telegraf/Influxdb URL issue 向 influxdb 发送数据时,telegraf 是否会自动附加时间戳? - Does telegraf automatically attach timestamp when sending data to influxdb?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM