[英]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.