LoginSignup
23
23

More than 5 years have passed since last update.

fluentdをmacにインストールしてとりあえず使ってみる

Last updated at Posted at 2013-03-20

Gemを使ってistall(Ruby1.9.2以上が必要)

gem install fluentd --no-ri --no-rdoc

起動
fluentd --setup ./fluent
fluentd -c ./fluent/fluent.conf -vv &

デーモンで起動させることも可能

confファイル

source -> 標準入力、ファイル、ポート指定のHTTP通信など

# $ echo <json> | fluent-cat <tag>
<source>
    type forward
</source>

# http通信
<source>
    type http
    port 8888
</source>

# ファイル
# 例ではapacheのaccess-log
<source>
    type all
    format apache
    path /var/log/httpd-access.log
    tag apache.access
</source>

# デバッグ出力
<source>
    type debug_agent
    port24230
</source>

match -> マッチしたログの処理 標準出力、ファイル出力、他サーバへの転送など

## tagがapache.accessのときpathにファイル出力
<match apache.access>
    type file
    path /var/log/fluent/access
</match>

## tagがdebug.** (**はワイルドカード??)のとき標準出力
<match debug.**>
    type stdout
</match>

## tagがsystem.**のとき他のサーバに転送
<match system.**>
    type forward
    host 192.168.0.11
    <secondary>
        host 192.168.0.12
    </secondary>
</match>

## tagがmyapp.**のとき他サーバのファイルに保存andファイルに保存(出力先複数)
<match myapp.**>
    type copy
    <store>
        type forward
        host 192.168.0.13
        buffer_type file
        buffer_path /var/log/fluent/myapp-forward
        retry_limit 50
        flush_interval 10s
    </store>
    <store>
        type file
        path /var/log/fluent/myapp
    </store>
</match>

## tagがfluent.**のとく何もしない
<match fluent.**>
    type null
</type>

## マッチしなかったもの(else的な)はgzip圧縮してファイル出力
<match **>
    type file
    path /var/log/fluent/else
    compress gz
</match>

include ->confファイルの読み込み。他サーバからも

include config.d/*.conf
include http://pokopoko.com/fluent.conf

使ってみる

echo '{"hoge":"fuga"}' | fluent-cat debug.forward

で元のコンソールに

2013-03-20 11:06:03 +0900 debug.forward: {"hoge":"fuga"}

のように標準出力される

curl http://localhost:8888/debug.http -F 'json={"foo":"bar"}'

するとリクエストを受け取り

2013-03-20 11:07:44 +0900 debug.http: {"foo":"bar"}

と出力

23
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
23