続き
- 前回は
sensu serverのログをfluentd→norikraで眺めてみた - 今回は
sensuの監視イベントを fluentd ハンドラプラグインからnorikraという流れを作ってみる - 前回同様に
sensuのデバッグやリアルタイムなイベント監視等に応用出来そうかな
準備
sensu の fluentd ハンドラプラグインの設定
repeatedly さんが作られたこちら と こちらを利用させて頂く。
cd /etc/sensu/handlers curl -k -o fluentd.rb https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/handlers/notification/fluentd.rb chmod 755 fluentd.rb cd /etc/sensu/conf.d/ curl -k -s -o fluentd.json https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/handlers/notification/fluentd.json
fluentd.json のみを fluentd の環境に応じて修正する必要があるが今回は http のポート番号のみを変更した。
{ "fluentd": { "host": "localhost", "port": 9800, "tag_prefix": "sensu" } }
fluentd(td-agent) 側の設定
input プラグインで http を使うことになる。
<source>
type monitor_agent
bind 0.0.0.0
port 24220
</source>
<source>
type http
port 9800
</source>
<match sensu.*>
type copy
<store>
type file
path /tmp/test.log
</store>
<store>
type norikra
# Please change your norikra server's IP
norikra localhost:26571
target_map_tag yes
</store>
</match>
<match norikra.**>
type stdout
</match>
monitor_agent は個人的な趣味です。
あとはお好きに...クエリ投げたりしてみて
前回とは異なり sensu server のイベントデータのみが fluentd を介して norikra に流れるようになるのでクエリの結果は少ないものの以下のようにイベントデータを見ることが出来る。

例えば、監視項目ごとにクエリ書いておいて件数見たりすることでリアルタイムに監視イベントのトレンドをキャッチアップ出来るのではないかと期待している。
おまとめ
今回の構成
以下のように sensu server 自身のログやイベントデータを fluentd を介して norikra に流し込み SQL ライクな DSL を使ってデバッグで利用したりリアルタイムの監視イベントの確認が出来るような構成を作ってみた。

試してみて
前回も書いたが sensu がイベントデータやログまでも JSON という共通言語でやりとりされていることにより fluentd との相性が良く、ログデータやイベントデータを簡単に fluentd を介して fluentd の各種プラグインでやりたい事がやれそうな気がした。また sensu の community plugin を組み合わせることで同じような目的を達成することも出来るとは思うが様々なツールを組み合わせる事ができる sensu の自由度と柔軟性の高さの良い部分ではないかと考えている。
色々と楽しいですな。