3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Splunk: statsとevalの使い分け

Posted at

時々微妙に迷うのでメモ。

実施環境: Splunk Free 8.2.2

Splunkには eval と stats という2つのコマンドがあり、 eval は[評価関数(Evaluation functions)] (https://docs.splunk.com/Documentation/Splunk/8.2.2/SearchReference/CommonEvalFunctions)、 stats は[統計関数(Statistical and charting functions)] (https://docs.splunk.com/Documentation/Splunk/8.2.2/SearchReference/CommonStatsFunctions)を使用することができます。
この2つは全く別物ではありますが、一見似たような処理を行う関数も多いため、どちらを使用すればよいか迷うこともあります。
さて、ではどのように使い分けるべきか。
結論から言いますと、「横に処理(単一のイベント内に閉じて処理)」する場合は eval 、「縦に処理(複数のイベントにまたがって処理)」する場合は stats を使用します。

以下のダミーデータを例にしてみます。

Splunk
| makeresults count=3
| streamstats count AS Test1
| eval Test2 = Test1 + 3, Test3 = Test1 + 6
| fields - _time, Test

スクリーンショット 2021-10-04 21.58.52.png

stats を使用した場合、処理は「縦に」行われ、結果のみが表示されます。

Splunk
| makeresults count=3
| streamstats count AS Test1
| eval Test2 = Test1 + 3, Test3 = Test1 + 6
| fields - _time, Test
| stats sum(Test1), sum(Test2), sum(Test3)

スクリーンショット 2021-10-04 21.59.44.png

eval を使用した場合、処理は「横に」行われ、結果は既存項目に追加する形で表示されます。

Splunk
| makeresults count=3
| streamstats count AS Test1
| eval Test2 = Test1 + 3, Test3 = Test1 + 6
| fields - _time, Test
| eval TestSum = sum(Test1, Test2, Test3)

スクリーンショット 2021-10-04 22.00.34.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?