LoginSignup
2
1

More than 3 years have passed since last update.

Splunk 過去と最近を比較する

Last updated at Posted at 2020-06-14

小ネタ
https://community.splunk.com/t5/Splunk-Search/How-to-count-data-from-different-time-and-use-it-in-the-same/m-p/504308/highlight/false#M140775

で回答したので。

ある期間と、今日の値を時系列で比較したい場合のやり方

timechart.spl
| tstats count where index=_internal earliest=1 by _time span=30min
| eval status="OverTime"
| append [|tstats count where index=_internal earliest=-1d@d by _time span=30min | eval status="Today"]
| eval _time=strftime(_time,"%T")
| stats avg(count)  as count by _time status
| xyseries _time status count
| fillnull OverTime Today

結果

_time OverTime Today
00:00:00 3147.4166666666665 0
00:30:00 2295.235294117647 0
01:00:00 2218.2 290.5
01:30:00 3621 818
02:00:00 6259.8 6103
02:30:00 4775.7 8777
03:00:00 3919.470588235294 145
03:30:00 4572 218
04:00:00 6751.25 4705

解説

  • tstatsは検索期間を複数設定できないのでappendでくっつけています。
  • その際evalで区分を作成
  • 結合するために、時間だけのデータにしています。
  • 二番目の引数のフィールドの値が列名となるxyseriesを使ってみました。
  • xyseriesだと値がないところを補完してくれないのでfillnullを使いました。

まとめ

列1 列2 列3
時間 あとで値を列名にしたいフィールド 集計値

という形を作るとxyseriesがいい感じで使えます。
binしてstats count by _time fieldappendでくっつけるとこの形が作れますね。

Splunk>Answersの質問者はappendcolsを使ってますけど、単純に横に列をくっつけるだけなので、だったらjoinのほうがいいですよね。

このごろはxyseriesをよく使っているような気がしています。
Splunkのtableの縦横を変換する
の頃はあんまり使ってなかったのに、慣れでしょうかね。

:sweat:逆にtimechartが使い辛くなってきた。

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