Upload
naotoshi-seo
View
29.876
Download
8
Embed Size (px)
Citation preview
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
InfluxDB の概要
June 27th, 2014 !Naotoshi Seo @sonotsDeNA Co., Ltd.
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
2
自己紹介・瀬尾 直利 @sonots ・DeNA Co., Ltd ・インフラのDev ・Rubyist ・OSS 活動家 ・Fluentd コミッタ
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
⁃ ログを処理するアプリケーション(or フレームワーク) ⁃ Ruby プラグインの仕組みが強力 (+250 plugins) ⁃ InfluxDB との連携もできます!(fluent-plugin-influxdb)
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
⁃ グラフツール ⁃ HTTP POST するだけ ⁃ ストレージは RRDtool
http://kazeburo.github.io/GrowthForecast/
GrowthForecast
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
http://blog.livedoor.jp/sonots/archives/29646713.html
Yohoushi!
分散 GrowthForecast グラフツール
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
InfluxDB
10
!
⁃時系列データベースの1つ ⁃ 時系列データを格納するのに適したデータベース ⁃ メトリクスやイベントの保存や解析に便利
⁃ Paul, Todd, John の三人がフルタイムで開発している (Y Combinator の出資を受けている)
⁃ golang ⁃ 2013年の Open Source Rookies に選ばれた
http://influxdb.com/
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
InfluxDB の特徴
11
!
!
• バックエンドに LevelDB を使っている ※ 抽象レイヤーもできました
• HTTP API でクエリを投げる • database と series (RDBMS でいう table のようなもの) の2階層
• スキーマレス • 分散ストレージ • (やたらと)豊富なクライアントライブラリ
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
豊富なクライアントライブラリ
12
• JavaScript • Ruby • Python • Node.js • PHP • Java • Clojure
http://influxdb.com
• Common Lisp • Go • Scala • R • Perl (by @hirose31) • Haskell
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
何に使うか(具体例)
14
!
• システムメトリクスの保存 • アクセスログの集計や解析 • RRDtool の置き換え • MySQL でやっている時系列データ解析置き換え
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
時系列データベース一覧
15
http://en.wikipedia.org/wiki/Time_series_database より
• Druid • Geras • InfluxDB • KairosDB • KDB+ • OpenTSDB • SiteWhere • TempoDB • Treasure Data(?)
• RRDtool • Graphite
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
データ登録
17
!
POST to /db/<database>/series?u=<user>&p=<pass>.
[ { "name" : "hd_used", "columns" : ["time", "value", "host"], "points" : [ [1400425947368, 23.2, "serverA"] ] } ]
request body ※ timeを指定しない場合は現在時間
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
クエリ
18
!
GET to /db/<database>/series?q=<query>&u=<user>&p=<pass>.
select * from log_lines limit 1
<query>
response body[ { "name": "log_lines", "columns": ["time", "sequence_number", "line"], "points": [ [1400425947368, 287780001, "here's some useful log info"] ] } ]
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
クエリサンプル
19
InfluxDB をちょっとさわってみた - (ひ)メモ http://d.hatena.ne.jp/hirose31/20140404/1396596668
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
時刻で範囲指定
20
[ { "columns": ["time","sequence_number","reqtime","url"], "name": "web9999.httpd", "points": [ ["1392030886","60703580001","0.21","/view/entry"], ["1392030885","60703560001","0.07","/login/error"], ["1392030884","60703540001","0.32","/login/"], ... ] } ]
select reqtime, url from web9999.httpd where time > now() - 1h limit 1000;
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
値で絞り込み(where)
21
[ { "columns": ["time","sequence_number","reqtime","url"], "name": "web9999.httpd", "points": [ ["1392030885","60703560001","0.07","/login/error"], ["1392030884","60703540001","0.32","/login/"], ["1392030881","60703480001","0.78","/login/error"], ... ] } ]
select reqtime, url from web9999.httpd where reqtime > 2.5;
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
値で絞り込み(正規表現)
22
[ { "columns": ["time","sequence_number","reqtime","url"], "name": "web9999.httpd", "points": [ ["1392030883","60703520001","2.81","/list/entry"], ["1392030878","60703420001","2.72","/view/entry"], ["1392030877","60703400001","2.94","/login/error"], ... ] } ]
select reqtime, url from web9999.httpd where url =~ /^\/login\//;
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
複数Series指定(正規表現)
23
[ { "columns": ["time","sequence_number","sys","user"], "name": "web9999.cpu", "points":[ ["1392030886","60703590001",3,57], ["1392030885","60703570001",9,1], ["1392030884","60703550001",28,42], ... ] } { "columns": ["time","sequence_number","reqtime","url"], "name": "web9999.httpd", "points": [ ["1392030886","60703580001","0.21","/view/entry"], ["1392030885","60703560001","0.07","/login/error"], ["1392030884","60703540001","0.32","/login/"], ... ] } ]
select * from /web9999\..*/;
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
複数Seriesへの問い合わせをMergeする
24
[ { "columns": ["time","sequence_number","reqtime","url","_orig_series"], "name": "web9999.httpd_merge_web0001.httpd", "points": [ ["1392030886","60706000001","1.09","/view/entry","web0001.httpd"], ["1392030886","60703580001","0.21","/view/entry","web9999.httpd"], ["1392030885","60705980001","1.53","/login/error","web0001.httpd"], ... ] } ]
select reqtime, url from web9999.httpd merge web0001.httpd;
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
group by (ダウンサンプリング)
25
select mean(sys) from web9999.cpu group by time(15m);
15分ごとの平均値!
╭( ・ㅂ・)و ̑ ̑
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
使える Statement
26
!
• Group by • Merge (series を複数指定して結果をマージする機能) • Limit • Join • Order (time フィールド専用の Order by)
• Explain
╭( ・ㅂ・)و ̑ ̑
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
使えない Statement
27
!
• Having • サブクエリ • Order by (今はまだカラムにインデックス利かないので...)
!
( ・д᷄・ ᷅)
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
使える集約関数
28
!
• Count, Min, Max, Mean, Mode, Median • Distinct • Percentile, Histogram, Derivative • Sum, Stddev, First/Last • DIfference, Top/Bottom (v0.6)
!
Derivative (時間微分) とか便利
╭( ・ㅂ・)و ̑ ̑
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
使えない集約関数
29
!
• 豊富な Built-In 集約関数 • ユーザ定義できない (UDFの仕組みがない)
( ・д᷄・ ᷅)
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Continuous Query
31
select percentile(value, 95) from response_times group by time(5m) into response_times.percentiles.5m.95; !select count(type) from events group by time(10m), type into events.count_per_type.10m;
クエリをあらかじめ仕込んでおくと、 逐次的にデータを別のSeriesに格納してくれる
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Fanout Continuous Query
32
select * from events into events.[page_id];
• 格納先 Series の名前が動的に定まる • Seriesを分けてインデックス代わりにするための機能
※ group by, join, merge, where と一緒に使えません
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Administration
33
• 3つのロール • Cluster Admin
• データベースを追加削除できる • Database admin と user を追加削除できる • クエリは投げれない
• Database Admin • Database admin と user を追加削除できる • write/read パーミッションを変更できる
• Database User • カレントデータベースを読み書きできる
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Graphite Protocol
34
http://influxdb.com/blog/2014/03/24/influxdb_v0_5_0_ready_for_production.html
• Input Plugin をサポート • もう、HTTP だけじゃない • Graphite Plugin • UDP Plugin
• Graphite (欧米で人気) をすでに使っているシステムを InfluxDB に移行しやすくする狙い
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Abstract Storage Engines
35https://github.com/influxdb/influxdb/tree/master/src/datastore/storage
http://influxdb.com/blog/2014/06/20/leveldb_vs_rocksdb_vs_hyperleveldb_vs_lmdb_performance.html
抽象レイヤーが入ってLevelDBだけじゃなくなった
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
クラスタリング/Shard
36
• ドキュメントがない\(^o^)/ • config_sample.toml に設定項目はある
@chobi_e さんの発表に期待(・ω<) テヘペロ
※ 後記:こちらです https://speakerdeck.com/chobie/influxdb-internals-1
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
38
• カラムにインデックス利かないので遅い • LevelDB だと key (id,時間,sequence) にしかインデックスきかない
• 集約関数は豊富だけど UDF 定義できない • Having, サブクエリ, Order by 使えない... • RRDtool のように古いデータを自動で消す事はできないのでバッチで消す...?
思ったこと
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Binary Protocol
40
!
!
• Protobuf / Msgpack / BSON • Asynchronisity • PubSub
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
PubSub Interface
41
!
!
• クエリを subscribe しておくと、 • データが入ってくるようなインターフェース
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Column Indexes
42
!
!
• カラムにインデックス貼りたい! • タグカラムを用意したいらしい • データにタグを貼る
• ついでに、1カラムに複数データを入れられる Array 型もサポートしたいらしい
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Shard Spaces and Retention Policies
43
!
• 保持期間を決めてそれが過ぎたらデータを捨てる • RRDtool 的な(ryshardSpaces = [ ! {name: "raw", retention: "4h"}, ! {name: "week", retention: "7d"}, ! {name: "month", retention: "30d"}, ! {name: "year", retention: "365d"}, ! {name: "keep", retention: "inf"} !]
// apply these rules for shard spaces !rules = [{ "database": "metricsDB", ! "mappings": [ ! {"space": "week", "regex": "^week.*"}, ! {"space": "month", "regex": "^month.*"}, ! {"space": "year", "regex": "^year.*"}, ! {"space": "keep", "regex": "^keep.*"}, ! {"space": "raw", "regex": ".*"} ! ] }]
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Custom Function
44
!
!
• ユーザ定義関数 (UDF) • Lua Scripts ...
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Security Enhancements
45
!
!
• where custom_id = 3 にマッチするデータだけ許可とか {
"readPermissions": [ { "matcher": ".*" }, { "name": "customer_events", "whereClause": "where customer_id = 3" } ], "writePermissions": [ { "name": "customer_events", "valueRestrictions": { "customer_id": 3 } } ] }
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Merging Many Series into One
46
!
• select * from merge /stats.*/ • 正規表現で指定できるようにしたいらしい !
※下のような merge はすでにできる select * from series1 merge series2
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
(ついでに) ダッシュボード紹介
47
Elasticsearch に対する Kibana のような
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
まとめ
51
• InfluxDB の概要を説明しました • Input Plugin の仕組みが出来て、HTTP API だけではなく、Graphite, UDP でもデータ投入できる
• group by, join は使えるが、having, サブクエリ, order by などはまだ使えない
• 抽象ストレージレイヤーができたのでストレージによってはカラムにインデックスが利くようになるかも
• Future に期待
Copyright (C) 2014 DeNA Co.,Ltd. All Rights Reserved.
Appendix: 情報源
53
• デザインゴール • http://influxdb.com/docs/v0.7/introduction/overview.html • https://github.com/influxdb/influxdb/blob/master/design_notes.md
• config_sample.toml • https://github.com/influxdb/influxdb/blob/master/config.sample.toml • 設定ファイルを読むとドキュメントに書いてないようなのが書いてあったり....
• Community • http://influxdb.com/community • メーリングリストに入って、@jvshahid, @toddpersen, and
@pauldix の三人を follow しておくとよさそう • Paul Dix - Internals of InfluxDB • http://pivotallabs.com/paul-dix-internals-influxdb/