fluentdをログ集約サーバとして使った時のメモ
まだ探り探りなのでもし良い方法があれば教えてください。
fluentd(td-agent)インストール用レシピ
excuteは使いたくなかったのですが一旦こちらで進めています。
execute 'Install td-agent' do command "curl -L #{node['td-agent']['install']['url']} | sh" not_if 'rpm -q td-agent' end template "/etc/td-agent/td-agent.conf" do owner 'root' mode 0644 source "#{node['td-agent']['conf']}.erb" notifies :reload, 'service[td-agent]' end node['td-agent']['server']['gem']['plugin'].each do |plugin| execute 'Install fluent-plugin-#{plugin}' do command "#{node['td-agent']['server']['gem']['dir']} install fluent-plugin-#{plugin}" not_if "#{node['td-agent']['server']['gem']['dir']} list | grep #{plugin}" end end service 'td-agent' do action [:enable, :start] supports restart: true, reload: true, status: true end
attributeやtemplateはこれに合わせて設定しています。割愛します。
各サーバから集めたログを同時書き込み
<match hoge.log.**> type file path /hoge/logs/foo.log output_time false </match>
各サーバからhogeというジャンルのlogをどのサーバから送ったかわかるようなtag設計にして送出するようにしています。hoge.log.
forest+ file_alternativeだと同時書き込みが・・・
tagごとのbuffer_pathがかぶるとNGのため同時書き込みが・・・。もう一つプラグイン挟めば良いと思うのですが、素直にtype fileにしました。
<match hoge.log.**> type forest subtype file_alternative remove_prefix hoge.log <template> path /hoge/logs/foo.log output_data_type attr:message output_include_tag true output_include_time false add_newline true </template> </match>
plain text状態のログ先頭にtagの一番後ろを付与(ohaiで取ったhostnameにしています)。pathでhogeというジャンルのlogということがわかるのでremove_prefixでtagから抜いています。
symlinkはbuffer_typeがfileの時のみ有効
buffer_type file buffer_path /fuga/logs/bar.buf symlink_path /fuga/logs/bar.log
http://docs.fluentd.org/articles/buf_file
buffer_type (required) The value must be file.
td-agentで集めたログのローテーションをどうするか
- time_sliceで期間を指定してローテーションされるが、logrotateのように世代管理ができないので・・・
- time_sliceをnoneとしたいが・・・
このあたりを使うのが良いのでしょうか。検討中。
find /hoge/logs/ -mtime +1
シェアして頂けると嬉しいです。
参考になったという方がいれば是非お願いしますm(_ _ )m
モチベーション維持の観点で非常に励みになります。
サーバ/インフラエンジニア養成読本 ログ収集〜可視化編 [現場主導のデータ分析環境を構築!] Software Design plus
- 出版社/メーカー: 技術評論社
- 発売日: 2014/08/14
- メディア: Kindle版
- この商品を含むブログを見る
【改訂新版】 サーバ/インフラエンジニア養成読本 管理/監視編 [24時間365日稼働を支える知恵と知識が満載!] (Software Design plus)
- 作者: 養成読本編集部
- 出版社/メーカー: 技術評論社
- 発売日: 2014/04/11
- メディア: 大型本
- この商品を含むブログ (3件) を見る