tsvのログをtd-agentで、mongodbにぶちこむメモ

前提

mongodb側

(インストールは終わったものとして)

とりあえず動くだけの設定

vim /etc/mongod.conf
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid
net:
  port: 27017
  bindIp: xxx.xxx.xxx.xxx

mongod開始

sudo service mongod start

agent側

td-agent導入

curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sudo sh

td-agentの設定を書く

vim /etc/td-agent/td-agent.conf
<source>
  type tail
  format tsv
  keys col1,col2,col3
  tag hoge.fuga
  path /var/log/hoge/hogehoge.%Y-%m-%d
  pos_file /tmp/hoge.pos
</source>
 
<match hoge.**>
  @type mongo
  host xxx.xxx.xxx.xxx
  port 27017
  database hogedb
  collection hogelog
  capped
  capped_size 1024m
  flush_interval 10s
</match>
 
<match fluent.**>
  @type mongo
  host xxx.xxx.xxx.xxx
  port 27017
  database hogedb2
  collection hogelog2
  capped
  capped_size 1024m
  flush_interval 10s
</match>

agent開始

sudo service td-agent start

こんな感じで設定すれば、ログが入っていく