Splunk Search

avg value of a field based on the range of another field

Da_Vicki
Engager
Logs :

Size    ExecValue
3       400
4       200 
13      150
2       300

Output:

     Size      avg(ExecValue)   max(ExecValue)
     0-5       300              400 
     6-10      0                0
    11-15     150               150

How can i achieve the above result?

Tags (4)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Sure, you can do this:

base search | bin span=5 Size | stats avg(ExecValue) max(ExecValue) by Size | makecontinuous Size | fillnull

Here's a dummy query generating sample data to test:

| stats count | eval value = "2 3 4 13" | makemv value | mvexpand value | eval foo = random() % 100 | bin span=5 value | stats avg(foo) max(foo) by value | makecontinuous value | fillnull

Dummy output:

    value   avg(foo)  max(foo)
1     0-5 53.000000         73
2    5-10         0          0
3   10-15 95.000000         95

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Sure, you can do this:

base search | bin span=5 Size | stats avg(ExecValue) max(ExecValue) by Size | makecontinuous Size | fillnull

Here's a dummy query generating sample data to test:

| stats count | eval value = "2 3 4 13" | makemv value | mvexpand value | eval foo = random() % 100 | bin span=5 value | stats avg(foo) max(foo) by value | makecontinuous value | fillnull

Dummy output:

    value   avg(foo)  max(foo)
1     0-5 53.000000         73
2    5-10         0          0
3   10-15 95.000000         95
Get Updates on the Splunk Community!

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...