elasticsearchのtimestampとkibanaでのtimestampがずれてしまう
filebeatのmoduleを使っていて, Kibanaで見てみると未来のデータありました(笑)
サーバーのlogは JST,
Elasticsearchは UTC,
Kibanaは JST
となる
未来のデータを見てみると, どれも/var/log/messages, /var/log/secure だけだった.
よくよく見ると, サーバーのlogの時刻をUTCに変換せずにElasticsearchに入り, Kibanaに+09:00されたデータが入っているようだ.
syslogのmoduleがおかしそうだな
調べて見ると, moduleはIngest Nodeというものを使っていて, 各moduleの下のingest/ 以下の.jsonに設定があるようだ
参考にしたサイト
https://discuss.elastic.co/t/filebeat-assumes-utc/80896
上記のサイト参考に /usr/share/filebeat/module/system/syslog/ingest/pipeline.json を書き換えてみる
# vi /usr/share/filebeat/module/system/syslog/ingest/pipeline.json
変更前
"date": { "field": "system.syslog.timestamp", "target_field": "@timestamp", "formats": [ "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ], "ignore_failure": true }
変更後
"date": {
"field": "system.syslog.timestamp",
"target_field": "@timestamp",
"timezone": "Asia/Tokyo",
"formats": [
"MMM d HH:mm:ss",
"MMM dd HH:mm:ss"
],
"ignore_failure": true
}
ちなみに"timezone": "JST"だとエラーが出てダメだった...orz
上記のように編集したらElasticsearchの古いpipeline情報を削除します
# curl -XDELETE http://<yourIP>:9200/_ingest/pipeline/filebeat-5.5.0-system-syslog-pipeline
次にfilebeatを再起動してお終い!
# systemctl restart filebeat
一度elasticsearch側に登録さえしてしまえば, 他のサーバのfilebeatは再起動するだけでok
僕は,サーバごとでfilebeatのバージョンが違って少し詰まってしまいました(笑)
起動しているかも確認
# systemctl status filebeat
pipelineがちゃんと設定されてたかも見てみる
# curl -XGET http://<yourIP>:9200/_ingest/pipeline/filebeat-5.5.0-system-syslog-pipeline
{"filebeat-5.5.0-system-syslog-pipeline":{"description":"Pipeline for parsing Syslog messages.","on_failure":[{"set":{"field":"error","value":"{{ _ingest.on_failure_message }}"}}],"processors":[{"grok":{"field":"message","ignore_missing":true,"pattern_definitions":{"GREEDYMULTILINE":"(.|\n)*"},"patterns":["%{SYSLOGTIMESTAMP:system.syslog.timestamp} %{SYSLOGHOST:system.syslog.hostname} %{DATA:system.syslog.program}(?:\\[%{POSINT:system.syslog.pid}\\])?: %{GREEDYMULTILINE:system.syslog.message}","%{SYSLOGTIMESTAMP:system.syslog.timestamp} %{GREEDYMULTILINE:system.syslog.message}"]}},{"remove":{"field":"message"}},{"date":{"field":"system.syslog.timestamp","formats":["MMM d HH:mm:ss","MMM dd HH:mm:ss"],"ignore_failure":true,"target_field":"@timestamp","timezone":"Asia/Tokyo"}}]}}
設定が反映されていることがわかる
kibanaからもちゃんとできていることが確認できた