追記
追記(1)Failed: Incorrect syntax near 'output' (a reserved keyword) のエラー
はじめに
- タイトル通り
sensu server
を検証するあたりログをチラチラ見れたら嬉しいよね- しかもせっかくログまでも
JSON
なsensu
はfluentd
との相性は抜群!ということで試した
準備
- 細かい設定については割愛させて頂きます...
- 既に稼働している
sensu server
にtd-agent
とnorikra
をインストールする - 以前に作った Dockerfile を一部流用
fluentd.conf(td-agent.conf)
今回は td-agent
を利用したので td-agent.conf
は以下のような感じでシンプルに。
<source> type monitor_agent bind 0.0.0.0 port 24220 </source> <source> type tail format json path /var/log/sensu/sensu-server.log tag sensu.streame pos_file /tmp/fluentd.pos </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>
起動
準備も整ったところで関係者(sensu server
や td-agent
や norikra
)を起動していく。
norikra
norikra
には Web
のダッシュボードが備わっているのでブラウザから確認することが出来る。今回は MacOS X
の boot2docker
を使っているので Web
ダッシュボードにバインドされたポートに対してブラウザからアクセスする。
その他の関係者の起動については追って書くかも。
sensu server のログ
Target
いよいよ松本伊代、本題の sensu server
のログ。関係者を起動後に暫くすると norikra
のダッシュボードの Target
に以下のように td-agent
経由で流れてくる sensu server
のログが登録されている。(※「登録」という言い方が正しいかは不安)
Query
簡単なクエリを投げてみる。
以下のような感じでクエリにマッチしたログが表示される。
また、コマンドラインからも...
norikra-client event fetch test1
と実行すると以下のようにクエリにマッチしたログが出力される。
{"time":"2014/04/07 20:15:04","timestamp":"2014-04-07T20:15:03.154364+0000","level":"info","message":"pruning aggregations"} {"time":"2014/04/07 20:15:14","timestamp":"2014-04-07T20:15:13.123437+0000","level":"info","message":"determining stale clients"} {"time":"2014/04/07 20:15:24","timestamp":"2014-04-07T20:15:23.157341+0000","level":"info","message":"pruning aggregations"} {"time":"2014/04/07 20:15:44","timestamp":"2014-04-07T20:15:43.125402+0000","level":"info","message":"determining stale clients"} {"time":"2014/04/07 20:15:44","timestamp":"2014-04-07T20:15:43.158266+0000","level":"info","message":"pruning aggregations"} {"time":"2014/04/07 20:15:52","timestamp":"2014-04-07T20:15:50.814024+0000","level":"info","message":"handling event"} {"time":"2014/04/07 20:15:54","timestamp":"2014-04-07T20:15:52.777894+0000","level":"info","message":"handling event"}
おお、便利そう。
最後に
まとまってないまとめ
- ログが
JSON
で流れてくると色々嬉しいかも Elasticsearch
等に放り込んでも検索等は出来るが「リアルタイム」と「SQLライクな検索が出来る」という点では norikra が優位だと思う
次回は
sensu
の fluentd イベントハンドラを介してnorikra
という流れを試してみたい
気になる点としては
output
というフィールド名を含むクエリを投げようとすると...
norikra-client query add test "select * from sensu_streame where output like '%check-disk.rb%'"
以下のようなエラーになってしまった。ガビーン。
2014-04-07 20:24:00 +0000 [INFO] : ClientError Norikra::QueryError: Incorrect syntax near 'output' (a reserved keyword) at line 1 column 34, please check the where clause [select * from sensu_streame where output like '%check-disk.rb%'] Failed: Incorrect syntax near 'output' (a reserved keyword) at line 1 column 34, please check the where clause [select * from sensu_streame where output like '%check-disk.rb%']
どうやら output
は予約語になっているようだ...。引き続き調べたいと思う。