Working with statistical functions - Mean, median and mode with the stats command
In this post, we will look at the statistical concepts of the measures of central tendency for numeric sets: mean, median and mode.
The mean is the sum of the values of all the elements in a numeric set divided by the number of elements in the set.
In Splunk terms, when we have a numeric field, all of its values are added up and the result is divided by the number of events that have this field. See the following example, using a field that records the number of bytes transferred in each transaction:
index=web | stats avg(bytes)
Here we can also use the by clause to group the calculated values by a specific field. In the following example, we see the average bytes grouped by IP address.
index=web | stats avg(bytes) by clientip
The mean doesn't always represent the data set well: when the elements are unevenly distributed, a single element can skew our set.
So we can use the mode as a measure of central tendency: the value that appears most often in a data set.
index=web | stats mode(bytes)
Another measure of central tendency we can calculate is the median, the middle value in a data set. To calculate the median we use the median parameter, as in the following example:
index=web | stats median(bytes)
Soon we will cover more functions of the stats command, as well as new SPL commands.
Want to practice? Try the free We Challenge sample, with Splunk questions and explanations.
To start from scratch, see the Introduction to Splunk course on Udemy (in Portuguese). For your team, see WeValuate's Splunk training.
Questions about the post? Content suggestions? Corrections? Criticism or praise?
Please contact us at wevaluatebr@gmail.com and we will reply as soon as possible.
If you liked it, share this post on your social networks and help us spread the word!



Comments