designetwork

ネットワークを軸としたIT技術メモ

FilebeatでNon-Zero Metricsのログを出さないようにする

こちらの記事に記載した通り、Beats(Filebeat)でログをシンプルにFluentdを送っている。

designetwork.hatenablog.com

その中で次のようなログが多発していることに気付いた。BeatsのMetrics監視の仕組みのようだが、安定稼働している状態では、常時発生するログは削減して異常ログのみを検知したい。

$ sudo tail -f /var/log/filebeat/filebeat
2017-07-09T13:36:09+09:00 INFO Non-zero metrics in the last 30s: filebeat.harvester.open_files=1 filebeat.harvester.running=1 filebeat.harvester.started=1 libbeat.logstash.call_count.PublishEvents=1 libbeat.logstash.publish.read_bytes=96 libbeat.logstash.publish.write_bytes=2224 libbeat.logstash.published_and_acked_events=16 libbeat.publisher.published_events=16 publish.events=17 registrar.states.update=17 registrar.writes=1
2017-07-09T13:36:39+09:00 INFO No non-zero metrics in the last 30s
2017-07-09T13:37:09+09:00 INFO No non-zero metrics in the last 30s
2017-07-09T13:37:39+09:00 INFO No non-zero metrics in the last 30s

このログが発生しないように設定を追加する。

Non-Zero Metricsのログを出さない設定

上記ログを抑止する設定は以下の通り。

$ sudo vi /etc/filebeat/filebeat.yml
filebeat.prospectors:
- input_type: log
  paths: ["/var/log/messages"]
#  symlinks: true
  fields:
    tagtype: linux
    tagapps: syslog
    taghost: centos7-m1
output.logstash:
  hosts: ["localhost:5044"]
#logging.level: debug
logging.metrics.enabled: false  //この設定を追加する

logging.metrics.enabledを無効化することにより、ログが出なくなる。設定変更しFilebeatを再起動するとログが出なくなる。

逆に細かく出す設定

ロギング間隔は変更することができる。

logging.metrics.enabled: true
logging.metrics.period: 10s  //デフォルト30s

このようにすると、10秒おきにログを出力することができる。ログの収集状況を詳細確認したいときなどに効果的。

2017-07-09T14:00:12+09:00 INFO Harvester started for file: /var/log/messages
2017-07-09T14:00:22+09:00 INFO Non-zero metrics in the last 10s: filebeat.harvester.open_files=1 filebeat.harvester.running=1 filebeat.harvester.started=1 libbeat.logstash.call_count.PublishEvents=1 libbeat.logstash.publish.read_bytes=6 libbeat.logstash.publish.write_bytes=365 libbeat.logstash.published_and_acked_events=3 libbeat.publisher.published_events=3 publish.events=6 registrar.states.current=2 registrar.states.update=6 registrar.writes=1
2017-07-09T14:00:32+09:00 INFO No non-zero metrics in the last 10s
2017-07-09T14:00:42+09:00 INFO No non-zero metrics in the last 10s

参考情報

オフィシャルにログに関する情報が記載されている。

www.elastic.co

また、デフォルトを含む全設定は/etc/filebeat/filebeat.full.ymlに記載されているため、1度目を通しておくと良いだろう。

$ sudo cat /etc/filebeat/filebeat.full.yml
######################## Filebeat Configuration ############################

# This file is a full configuration example documenting all non-deprecated
# options in comments. For a shorter configuration example, that contains only
# the most common options, please see filebeat.yml in the same directory.
#
# You can find the full configuration reference here:
# https://www.elastic.co/guide/en/beats/filebeat/index.html
...

まとめ - FilebeatでNon-Zero Metricsのログを出さないようにする

Filebeatのログ出力設定を変更することでNon-Zero Metricsのログを出力しないようにした。なお、必要に応じてログ出力頻度を上げることもできる。