LoginSignup
3
7

More than 5 years have passed since last update.

timelionのconditionを使おう

Posted at

timelionのconditionを使おう

軸にワンポイントで強調を入れられるらしい。あまりググってもでないので、試した結果を残しておく。

使用環境

  • elasticsearch 5.0.0-alpha3
  • Kibana5.0.0-alpha3

ポイント

ltやgtの演算子の比較対象が何かというところ。

たとえば、以下のような例を考える。

A.condition(lt, if=400).points(3, fill=3)

これは、 「Aの値 > 400」のとき、points(3, fill=3)をすることになる。
パッと見た感じでは、 A.condition(lt, if=400) と書いていると、 A < 400 になるかとおもいきや、そうではない様子。ifで書いた値がltなのか、gt、lte、gte、eqなのかというところ。
ここがポイント。

マニュアル上の記載

Compares each point to a number, or the same point in another series using an operator, then sets its valueto the result if the condition proves true, with an optional else.

Argument Accepts Description
operator string Operator to use for comparison, valid operators are eq (equal), ne (not equal), lt less than), lte (less than equal), gt (greater than), gte (greater than equal)
if number/seriesList The value to which the point will be compared. If you pass a seriesList here the first series will be used
then number/seriesList The value the point will be set to if the comparison is true. If you pass a seriesList here the first series will be used
else number/seriesList The value the point will be set to if the comparison is false. If you pass a seriesList here the first series will be used

ifで比較するのは、固定値でも取得した結果でも良いとのこと。

固定値で比較する

300を閾値として、300を超えている部分に○(circle)を入れる例。300 overとlabelを書いている部分。
300以下の部分のところは、非表示になっている。

.es(index='test', timefield='timestamp'), .es(index='test', timefield='timestamp').condition(lt, if=300).points(3, fill=5).color('#c66').label('300 over')

TimelionKibana_001.png

他の軸情報と比較する

if/then/elseはnumberかseriesListをとることができると。
例えば、1時間前の情報に比べて値が増減したときに、強調表示したい、というような場合。

ifのあとに、seriesList(.es()や、.quandl()など)を指定する。ここではoffsetを-1hとして、1時間前の値と比較することにした。

.es(index='test', timefield='timestamp', q='team:RESISTANCE').movingaverage(window=10), .es(index='test', timefield='timestamp', q='team:RESISTANCE').condition(lt, if=(.es(index='test', timefield='timestamp', q='team:RESISTANCE', offset=-1h))).points(3, fill=3).color('#c66')

TimelionKibana_002.png

then, elseを使う例

.condition(lt, if=300, then=200) とすると、

300を超えている部分は、そのまま。300以下の部分は、200として値が使われる。その値に対して、グラフが描画されるため以下のようになる。

.es(index='test', timefield='timestamp'), .es(index='test', timefield='timestamp').condition(lt, if=300, then=200).points(3, fill=5).color('#c66').label('300 over')

TimelionKibana_003.png

.condition(lt, if=300, then=200, else=500) とすると、

300以下の部分は、200として値が使われる。それ以外の値は、500として値が使われる。その結果以下のようになる。

.es(index='test', timefield='timestamp'), .es(index='test', timefield='timestamp').condition(lt, if=300, then=200, else=500).points(3, fill=5).color('#c66').label('300 over')

TimelionKibana_004.png

参考文献

公式マニュアル

おまけ

公式が出しているkibanaのDockerイメージに、timelionをつっこむ例。

FROM kibana:5.0.0-alpha3

RUN /opt/kibana/bin/kibana-plugin install timelion && \
    chown -R kibana:kibana /opt/kibana

kibanaユーザに所有権を変えておかないと、kibanaの起動時にPermissionで怒られることになる。
これを kibana5a3:latestというイメージにしたと仮定すると、起動方法はこんな感じ。

docker run -d -p 5601:5601 --name kibana5a3 --link elasticsearchを立ててるコンテナ名:elasticsearch kibana5a3:latest
3
7
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
3
7