Upload
kotake-d
View
387
Download
0
Embed Size (px)
DESCRIPTION
Sample search strings for Splunk. I hope this PPT make your splunk life happy.
Citation preview
マクニカネットワークス株式会社
2014/7/3
Search Freaks!!!!
• 様々な要件を実現すべく、これまでに多くの検索条件を作成してきました。
• 今回は、実現に際して実際に使った検索条件をいくつか紹介します。
• 状況によっては、そのまま使えない場合や、より効率の良い検索条件があり得ます。
はじめに
• 課題– データの存在しない分割要素に対しては、そもそも集計されない
現実理想月
水
木
土
日
強制的に毎日のイベント数をカウントする
月
火
水
木
金
土
日
• 月~日まで書かれたルックアップテーブル• 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
強制的に毎日のイベント数をカウントする
強制的に毎日のイベント数をカウントする
• 課題– timechart で集計した結果に対して where コマンドが適用できない
timechart の結果に閾値を設ける
40 以上のイベントは
どれ?
timechart の結果に閾値を設ける
where <field 名 > >= 数値
• timechart xxx by yyy で指定した yyy というフィールドの値として何が来るか分かっていれば、 where で閾値設定できる。
• どんなフィールド値が来るのか事前に把握できない場合、 where で閾値設定できるように、 timechart の結果を整形してあげる必要がある。
• untable コマンド
・・・ | timechart limit=10 useother=f bins=100 count by file | untable _time files count
timechart の結果に閾値を設ける
timechart の結果に閾値を設ける
where <field 名 > >= 数値
• 実は、最初から timechart を使わず、 bucket コマンドと statsコマンドを使うことでほぼ同様のことができます。
・・・ | bucket span=5m _time | stats count by file _time
timechart の結果に閾値を設ける
• ... | stats count by xxx• としたとき、結果は以下のようになる。
xxx count---------------ABC 2DEF 5GHI 3
任意の数値の分イベントを複製する
これを、以下のような結果にしたい。
ABCABCDEFDEFDEFDEFDEFGHIGHIGHI
| 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 というカンマを含んだ文字列に変換
| 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 イベントに分割
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
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
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
フィールド値毎にイベントを複製する