influxdb - 电报 : How collect Hexadecimal data and apply function before insert in influxdb?

标签 influxdb telegraf

我需要帮助读取十六进制数据并应用公式来转换数据。我的文件用尾部解析:

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

还有我的配置:

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

使用此配置,数据类型为“字符串”,我想将十六进制值转换为整数 (IN_01hexa) 并应用类似 01hexa_convert = ((IN_01hexa)*0.8125-4.25) 的更改。然后,在我的数据库中, 01hexa_convert 的类型必须是 float。

最佳答案

您可以尝试通过 Telegraf's converter plugin 将十六进制字符串转换为整数.

示例代码如下:

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

至于匹配处理部分,好像我们必须在Telegraf doesn't have such plugin yet的查询阶段做。 .

关于influxdb - 电报 : How collect Hexadecimal data and apply function before insert in influxdb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73844473/

相关文章:

sql-server - Azure SQL 数据库中的 SQL Server Telegraf 插件需要哪些拨款

python - 从 python 客户端发送带有标签的 statsD 指标

node.js - 使用 Telegram bot(telegraf),nodejs发送markdown文本

grafana - InfluxDB错误: default retention policy not set for database in grafana after influx update from 1 to 2

go - 如何使用 Go 外部插件与 Telegraf 交互?

kubernetes - 将电报作为守护进程运行

node.js - 如何使用 Telegram bot API 请求用户的实时位置?

apache-kafka - 有没有办法将数据从 InfluxDB 发送到 Kafka?

influxdb - Flux 查询语言中 SELECT <某些列> 的等价物是什么?

docker - Docker容器间通讯