LoginSignup
2
3

More than 3 years have passed since last update.

前の値と比較する

Last updated at Posted at 2019-12-22

小ネタ

はじめに

timechartで時系列の表を作って、30分前の値と比較したいとかの場合とか、いろいろな場合での前の値との比較方法をいろいろと

SPL
| makeresults count=2 
| streamstats count 
| eval _time = if (count==2,relative_time(_time,"-1h@m"), relative_time(_time,"@m")) 
| makecontinuous span=1m _time 
| eval count=random() % 100

データはこちらを使用

delta

Delta@Splunk>docs

| delta count as defference
_time count defference
2019/12/22 08:24:00 1
2019/12/22 08:25:00 55 54
2019/12/22 08:26:00 75 20
2019/12/22 08:27:00 29 -46

前の値との差分をだしてくれる。
p= を指定することでどれだけ前の値と比較するか指定できる。

autoregress

autoregress@Splunk>docs

| autoregress count
| eval perc=round(count/(count+count_p1)*100)."%"
| eval perc=case(count = count_p1,"±", count > count_p1,"+",count < count_p1,"-").perc
_time count count_p1 perc
2019/12/22 08:35:00 69
2019/12/22 08:36:00 32 69 -32%
2019/12/22 08:37:00 53 32 +62%
2019/12/22 08:38:00 35 53 -40%

deltaと違い、前の値をそのまま出すautoregress
こんな感じで前の値との比較を少し凝った形にしたい時に使う。
こちらも p= が指定できる。

:sweat_smile: ダッシュボードSingle valueで表示したら、自動でやってくれてるね。これ

streamstats

streamstats@Splunk>docs

| streamstats current=f last(count) as count_p1
_time count count_p1
2019/12/22 08:40:00 17
2019/12/22 08:41:00 88 17
2019/12/22 08:42:00 81 88
2019/12/22 08:43:00 89 81

autoregressの出力と同じにしてみた。
current=fがポイント。
autoregressとの違いは、条件をevalにて指定できること。
あとは window=が指定できるので、いろいろ応用が効く。

| streamstats current=f last(eval(if(searchmatch("hoge"),count,NULL))) as count_p1

文字列hogeがあるログの前の値とか指定できる。

まとめ

表(じゃなくてもいい)の順番をreverseとかsort 0で揃えて使うのが基本。
この3つのコマンドを使えば、前の値との比較は大丈夫 :sweat: かな

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