我需要帮助读取十六进制数据并应用公式来转换数据。我的文件用 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
我的配置:
[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 必须是浮点数。
小智 7
您可以尝试通过Telegraf 的转换器插件将十六进制字符串转换为整数。
示例代码如下:
[[processors.converter]]
    [processors.converter.fields]
         integer = ["*hexa"]
至于匹配处理部分,似乎我们必须在查询阶段进行,因为 Telegraf还没有这样的插件。
| 归档时间: | 
 | 
| 查看次数: | 438 次 | 
| 最近记录: |