mutao.net

いわゆる雑記。

td-agentでnginxのaccesslogを収集

前回apacheのtd-agentの設定は書いたけどnginxはまだ書いていなかったのでメモ。

<source>
  @type tail
  path /var/log/nginx/access.log
  format nginx
  tag nginx.access
  pos_file /var/log/td-agent/nginx.access.log.pos
</source>
<match nginx.access>
  @type elasticsearch
  host 127.0.0.1
  port 9200
  logstash_format true
  logstash_prefix nginx
  type_name accesslog
</match>

https://docs.fluentd.org/input/tail

Parameter value メモ
@type tail
path /var/log/nginx/access.log 取得するログのpath。「,」区切りで複数設定可能
tag nginx.access 後のmatchディレクティブで使用
pos_file td-agent(Fluentd)がログを読み取った位置を記載するファイル td-agentユーザの権限がある場所

https://docs.fluentd.org/output/elasticsearch

Parameter value メモ
@type elasticsearch
host elastic nodeが動作しているhost
port elastic nodeが動作しているport
logstash_format true logstash-%Y.%m.%dでindex nameが生成される。
logstash_prefix nginx logstash_format の 「logstash」部分を変更。
type_name elastic search の type