fluentdとダッシュボードを使った
ビジュアルなシステム管理
SITW24
2014-07-26
諸星佑樹 @hoshi_sano
おおまかな流れ
•背景 • ビジュアルなシステム管理はなぜ必要か
• fluentdとは何か
• Fluentdによる収集データの視覚化デモ
背景
クラウドな時代
→個人/サービス単位で利用するホスト数の増加
背景 インフラ構築、デプロイの自動化の重要性↑
例) Chef, Capistrano, …etc
背景
監視対象はたくさんある
ログ、CPU/メモリ使用率、各センサー値、…etc
背景
ただでさえ大変なのに、台数増えたらたまんないよ!
監視もなるべくシンプルにしたい!
(;ω;)
http://www.fluentd.org/architecture より
fluentdで!
http://www.fluentd.org/architecture より
fluentdとは
• (準)リアルタイムデータ収集システム
• Treasure Data
• ビッグデータのクラウドサービス
• Ruby製
• gem版: fluentd
•パッケージ版: td-agent
•中身は同じ
fluentdの特徴
• JSON & msgpack
•高速・コンパクト
• プラガブル Pluggable • さまざまなプラグインが多くの人の手によって開発されている
• プラグインリスト
• Routing, Retry, Scalable, …
データ構造
• tag (文字列)
• time (epoch)
• record (JSON)
‚syslog‛
1405924812
{
‚host‛: ‚myPC‛,
‚ident‛: ‚kernel‛,
‚message‛: ‚…‛
}
fluentdのデータの流れ
Input Plugin Engine
Input Plugin
Output
Plugin
Output
Plugin
(かなり雑に…)
ホントはここに
Buffer Pluginも
いるけど割愛
fluentdのデータの流れ
Input Plugin Engine
Input Plugin
Output
Plugin
Output
Plugin
tag
time
record
tag
time
record
tag
time
record
data
chunk
別のfluentdから
データが流れてきたり
ポーリングしたり
fluentdのデータの流れ
Input Plugin Engine
Input Plugin
Output
Plugin
Output
Plugin
tag
time
record
tag
time
record
タグを見てどのOutput
Pluginを使うか判定
fluentdのデータの流れ
Input Plugin Engine
Input Plugin
Output
Plugin
Output
Plugin
tag
time
record
tag
time
record
tag
time
record
chunk
tagやrecordを書き換えてengineに戻すものも。
Filter系のOutput Plugin
別のfluentdへデータを
送ったり、ストレージにデータを書き込んだり
Input と Output の組み合わせでいろんな応用が可能!
今日の主題
統一&視覚化
GrowthForecast
Elasticsearch + Kibana
共通点 client API storage
graph
user
process
共通点 client API storage
graph
user
process
GrowthForecast
共通点 client API storage
graph
user
process
Elasticsearch
Kibana
デモ環境
agent1(VM)
ホストマシン
agent2(VM)
GrowthForecastデモ 目指すもの
dstat
• サーバのリソース状況を取得するコマンド
• fluentdで送受信可能な形式に
• →GrowthForecastでグラフ化
fluent-plugin-dstat
<source>
type dstat
tag dstat
option -cm
delay 1
</source>
<match dstat>
type stdout
</match>
取得したデータにはこのタグをつけます
dstat実行時のオプションを指定します
とりあえず
出力してみます
fluent-plugin-dstatで得られたもの dstat {
"hostname":‚agent1",
"dstat":{
"total cpu usage":{
"usr":"0.215",
"sys":"0.436",
"idl":"99.301",
"wai":"0.033",
"hiq":"0.0",
"siq":"0.017"
},
"memory usage":{
"used":"77672448.0",
"buff":"12271616.0",
"cach":"40595456.0",
"free":"256532480.0"
}
}
}
タグ
• 値はちゃんと取れてる
• でもGrowthForecastが期待するデータ構造になってない • 厳密には、GrowthForecastへデータを送るためのPluginが期待するデータ構造でない
• ネストしてるのがダメ
fluent-plugin-map <match dstat>
type copy
<store>
type map
tag ‚dstat.agent1.cpu"
time time
record record['dstat']['total cpu usage']
</store>
<store>
type map
tag ‚dstat.agent1.mem"
time time
record record['dstat']['memory usage']
</store>
</match>
fluent-plugin-map dstat {
"hostname":‚agent1",
"dstat":{
"total cpu usage":{
"usr":"0.215",
"sys":"0.436",
"idl":"99.301",
"wai":"0.033",
"hiq":"0.0",
"siq":"0.017"
},
"memory usage":{
"used":"77672448.0",
"buff":"12271616.0",
"cach":"40595456.0",
"free":"256532480.0"
}
}
}
dstat.agent1.cpu {
"usr":"0.215",
"sys":"0.436",
"idl":‚99.301",
"wai":"0.033",
"hiq":"0.0",
"siq":"0.017"
}
dstat.agent1.mem {
"used":"77672448.0",
"buff":"12271616.0",
"cach":"40595456.0",
"free":"2565322480.0"
}
GrowthForecastへのデータストア
$ curl -F number=10 ¥
http://gfhost:5125/api/service/section/graph
JSONを投げると自動でグラフ化
fluent-plugin-growthforecast
<match dstat.**>
type growthforecast
gfapi_url http://localhost:5125/api/
service dstat-demo
tag_for section
remove_prefix dstat
name_key_pattern .*
</match>
http://gfhost:5125/api/service/section/graph
dstat.agent1.mem
{
"used":"77672448.0",
"buff":"12271616.0",
"cach":"40595456.0",
"free":"2565322480.0"
}
タグをsectionに
使うけども
タグからdstat
を除去します
GrowthForecast簡単で便利!
…だけど最近はあまり流行ってない?
• 数値しか受け付けない
• 再利用性がちょっと低い • JSONでグラフデータをエクスポートする機能はあるけど
fluentd + GrowthForecast参考情報
• GrowthForecast を CentOS 6.3 にインストールして Supervisor で管理してみた
• GrowthForecastというグラフ表示ツールで捗る話
• dstatをfluentd + GrowthForecastで可視化する
Elasticsearch + Kibana デモ 目指すもの
Elasticsearch
• 高速スケーラブル検索エンジン
• REST APIによるデータ操作
• スキーマレス • 各フィールドの型は自動で決定
• 「ちょっと試す」のが簡単 • zip/tar.gzを展開するだけですぐ使える
Elasticsearch
$ bin/elasticsearch [-d] [-p]
起動
$ curl -X PUT ¥
http://localhost:9200/blog/article/1 -d ¥
'{"title": "First Aritcle",
"content": "This is my 1st article.",
"tags": [‚tips", "elasticsearch"]}'
APIでデータストア
Elasticsearch
$ curl -X PUT ¥
http://localhost:9200/blog/article/1 -d ‘{...}’
インデックス ≒ RDBのデータベース
タイプ≒ RDBのテーブル
ドキュメント ≒ RDBのレコード
インデックス (ドキュメントの) タイプ
ID
Kibana
• Elasticsearchをバックエンドとしたログ視覚化ツール
• HTML、CSS、JSなどで構成 • webサーバに置けばすぐ使える
fluent-plugin-elasticserach
<smatch dstat.**>
type elasticsearch
host 127.0.0.1
port 9200
type_name dstat
logstash_format true
logstash_prefix dstat
logstash_dateformat %Y%m%d
include_tag_key true
tag_key _key
</match>
この設定でGrowthForecastのデモで使ったデータをそのまま
Elasticsearchにストアできる
Kibanaは元々logstashというログ収集ツールのフロントエンドだったため、
logstashのフォーマットと親和性が高い
• Elasticsearch + Kibanaでできることはデータのグラフ化だけではない
• クエリによるsyslogやapachelogのフィルタリング、時間毎のカウントなども可能
• だけど…
• GrowthForecastほどのお手軽感はない • 扱えるものが増えるのでそりゃ当たり前なんだけど
• 便利でかっこいいダッシュボードを作るには作りこみが必要
fluentd + Elasticsearch + Kibana
参考情報
• fluentd + Elasticsearch + Kibanaで始めるログ解析
• Kibana入門
• Kibana3を環境構築だけで終わらせない(前編)(後編)
応用編
詳細は話しませんが…
Zabbixとの連携(fluent-plugin-zabbix)
Norikra(stream processing with SQL)
アラート(有料サービス, IRC, mail, …)
ネットワーク監視(fluent-plugin-network-probeなど)