Splunk live @tokyo 小竹 LT 20140703

16
マママママママママママママママ 2014/7/3 Search Freaks!!!!

description

Sample search strings for Splunk. I hope this PPT make your splunk life happy.

Transcript of Splunk live @tokyo 小竹 LT 20140703

Page 1: Splunk live @tokyo 小竹 LT 20140703

マクニカネットワークス株式会社

2014/7/3

Search Freaks!!!!

Page 2: Splunk live @tokyo 小竹 LT 20140703

• 様々な要件を実現すべく、これまでに多くの検索条件を作成してきました。

• 今回は、実現に際して実際に使った検索条件をいくつか紹介します。

• 状況によっては、そのまま使えない場合や、より効率の良い検索条件があり得ます。

はじめに

Page 3: Splunk live @tokyo 小竹 LT 20140703

• 課題– データの存在しない分割要素に対しては、そもそも集計されない

現実理想月

強制的に毎日のイベント数をカウントする

Page 4: Splunk live @tokyo 小竹 LT 20140703

• 月~日まで書かれたルックアップテーブル• inputlookup コマンド

• join コマンド type=left

|inputlookup date_table | table date_wday | join type=left date_wday [search index=_internal source=*splunk* NOT (date_wday=friday OR date_wday=tuesday) earliest=-2w@w latest=-1w@w | stats count by date_wday] | fillnull value=0

強制的に毎日のイベント数をカウントする

Page 5: Splunk live @tokyo 小竹 LT 20140703

強制的に毎日のイベント数をカウントする

Page 6: Splunk live @tokyo 小竹 LT 20140703

• 課題– timechart で集計した結果に対して where コマンドが適用できない

timechart の結果に閾値を設ける

40 以上のイベントは

どれ?

Page 7: Splunk live @tokyo 小竹 LT 20140703

timechart の結果に閾値を設ける

where <field 名 > >= 数値

Page 8: Splunk live @tokyo 小竹 LT 20140703

• timechart xxx by yyy で指定した yyy というフィールドの値として何が来るか分かっていれば、 where で閾値設定できる。

• どんなフィールド値が来るのか事前に把握できない場合、 where で閾値設定できるように、 timechart の結果を整形してあげる必要がある。

• untable コマンド

・・・ | timechart limit=10 useother=f bins=100 count by file | untable _time files count

timechart の結果に閾値を設ける

Page 9: Splunk live @tokyo 小竹 LT 20140703

timechart の結果に閾値を設ける

where <field 名 > >= 数値

Page 10: Splunk live @tokyo 小竹 LT 20140703

• 実は、最初から timechart を使わず、 bucket コマンドと statsコマンドを使うことでほぼ同様のことができます。

・・・ | bucket span=5m _time | stats count by file _time

timechart の結果に閾値を設ける

Page 11: Splunk live @tokyo 小竹 LT 20140703

• ... | stats count by xxx• としたとき、結果は以下のようになる。

xxx count---------------ABC 2DEF 5GHI 3

任意の数値の分イベントを複製する

これを、以下のような結果にしたい。

ABCABCDEFDEFDEFDEFDEFGHIGHIGHI

Page 12: Splunk live @tokyo 小竹 LT 20140703

| eval temp = replace(tostring(round(pow(10, count-1),0)), "(\d)", "\1,") | makemv temp delim="," | mvexpand temp | fields - temp

任意の数値の分イベントを複製する

10 の (count-1) 乗

1000 という文字列を 1,0,0,0 というカンマを含んだ文字列に変換

Page 13: Splunk live @tokyo 小竹 LT 20140703

| eval temp = replace(tostring(round(pow(10, count-1),0)), "(\d)", "\1,") | makemv temp delim="," | mvexpand temp | fields - temp

任意の数値の分イベントを複製する

カンマ毎に temp というフィールドの値として分割

temp=1temp=0temp=0

というフィールド値が 1 イベントに複数生成される

フィールド値 1 つにつき 1 イベントに分割

Page 14: Splunk live @tokyo 小竹 LT 20140703

xxx count---------------ABC 2DEF 5GHI 3

• | eval temp = replace(tostring(round(pow(10, count-1),0)), "(\d)", "\1,")

任意の数値の分イベントを複製する

10000 → 1,0,0,0,0

10 の 4 乗 =10000

Page 15: Splunk live @tokyo 小竹 LT 20140703

xxx count---------------ABC 2DEF 5GHI 3

| makemv temp delim=","

5 つのフィールド値を持つイベントとなる

任意の数値の分イベントを複製する

2014/7/3 10:00:00 ip=172.21.63.1 url=www.google.co.jp action=xxxxxx

temp=1

temp=0

temp=0

temp=0 temp=0

Page 16: Splunk live @tokyo 小竹 LT 20140703

xxx count---------------ABC 2DEF 5GHI 3

| mvexpand temp

任意の数値の分イベントを複製する

2014/7/3 10:00:00 ip=172.21.63.1 url=www.google.co.jp action=xxxxxx temp=1

2014/7/3 10:00:00 ip=172.21.63.1 url=www.google.co.jp action=xxxxxx temp=0

2014/7/3 10:00:00 ip=172.21.63.1 url=www.google.co.jp action=xxxxxx temp=0

2014/7/3 10:00:00 ip=172.21.63.1 url=www.google.co.jp action=xxxxxx temp=0

2014/7/3 10:00:00 ip=172.21.63.1 url=www.google.co.jp action=xxxxxx temp=0

フィールド値毎にイベントを複製する