Splunk Search

How to calculate the average of a column, and display this average next to it in a separate column?

pavanae
Builder

I displayed the list of people and their count by using the below search:

foo | stats dc(A) as people by B

which displayed as follows

people      B 
asd         23
sdas        32

Now how can I calculate the average of all the values in B and display the average in another column?

1 Solution

cmerriman
Super Champion
foo | stats dc(A) as people by B|eventstats avg(people) as avgPeople|stats max(people) as people max(avgPeople) as avgPeople by B

something like this might be what you're looking for

View solution in original post

cmerriman
Super Champion
foo | stats dc(A) as people by B|eventstats avg(people) as avgPeople|stats max(people) as people max(avgPeople) as avgPeople by B

something like this might be what you're looking for

pavanae
Builder

now how can I display only the people with B values greater than avgPeople and also how to calculate their count?

0 Karma

cmerriman
Super Champion
foo | stats dc(A) as people by B|eventstats avg(people) as avgPeople|stats max(people) as people max(avgPeople) as avgPeople by B|where people>avgPeople

calculate what count exactly? did you want to just add count to the first stats command and add max(count) as totalCount to the second command?

0 Karma

pavanae
Builder

I would be really appriciate if you can suggest me a way to display a timechart which displays the avgpeople and people by B with time. @cmerriman

0 Karma

cmerriman
Super Champion
foo | stats dc(A) as people by B _time|eventstats avg(people) as avgPeople|timechart span=1d max(people) as people max(avgPeople) as avgPeople by B |where people>avgPeople

you might play around with the first stats command. maybe add a |bucket _time span=1d before it or something, depending on what your _time field looks like.

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...