LoginSignup
2
5

More than 5 years have passed since last update.

【Splunk】特定の条件下のデータが全体のどれくらいの割合なのかを表示する方法

Last updated at Posted at 2017-12-03

Splunkで、とある条件下のデータが全体のどれくらいの割合なのかを表示するやり方。

例えば、あるマラソン大会の選手とスコアのデータが下記のようにあったとする。
※ 名前、性別、記録(分単位)のデータがあり、Splunkには"runner"というインデックスで登録したとする

name,gender,finish_time
Bob,male,198
Mike,male,235
Kate,male,317
Jack,male,257
David,male,299
Noah,male,181
James,male,233
Alex,male,271
Alice,female,281
Emma,female,325
Amelia,female,245
Chloe,female,309
Lily,female,356
Amy,female,239

上記データからサブ4(4時間内で完走)した選手の割合を出すときのサーチ文は

index="runner" 
| eval class=if(finish_time<240, "sub_4", "other")
| stats count by class

となって、視覚エフェクトで円グラフを表示すると、こんな感じになります。

さらに、サブ4からサブ3.5(3.5時間で完走)した選手の割合も一緒に出したいときは

index="runner" 
| eval class=if(finish_time<210, "sub_3.5", if(finish_time>=210 AND finish_time<240, "sub_4", "other"))
| stats count by class

こんなサーチ文を実行すると、下みたいな円グラフを出せます。

Splunkはif文にelseがない(?)のか、
複数条件分岐をするときはマトリョーシカ的にやらないといけないのかもしれないです。

備忘までに。

2
5
2

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
2
5