fluentdをログ集約サーバとして使った時のメモ

f:id:komeiy:20150107164847j:plain

まだ探り探りなのでもし良い方法があれば教えてください。

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
モチベーション維持の観点で非常に励みになります。

このエントリーをはてなブックマークに追加