Json
包含 json 數據到 Influx 的 Telegraf Tail 文件
如何通過拖尾包含 JSON 數據的文件將 json 數據提取到 influx 中?
例如:
我的日誌是這樣的:
2020-12-01T18:34:06+02:00 10.132.90.194 {"wfd_successful_hits_sec": "0", "sql_hits_sec_max": "0", "timestamp": "2020/12/01 18:34:01", "connection_sec_max": "1922", "http_hits_sec_max": "1106", "http_hits_sec": "106", "wfd_successful_hits_sec_max": "0", "sql_hits_sec": "0", "sql_audit_phase2_events_sec_max": "0", "hdfs_hits_sec": "0", "connection_sec": "26"}
有沒有辦法只提取 JSON 部分並將其發送給 influx?
我知道 grok 模式
(\{.*\})$
會提取 JSON 部分。我的配置如下所示:
[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 = "" hostname = "" omit_hostname = false [[inputs.tail]] files = ["/opt/share/host*log"] data_format = "json" [[outputs.influxdb_v2]] urls = ["http://localhost:8086"] token = "TOKEN" organization = "ORG" bucket = "performance_stats
因為我的 JSON 輸出包含一個時間戳欄位。
我修改了我的 rsyslog 配置以保存 syslog
rawmsg
並從打開的第一場比賽開始保存{
$Template tpl,"%rawmsg:R,ERE,0,DFLT:(\{.*)--end%\n"