Use the stats command and functions (2024)

This topic discusses how to use the statistical functions with the transforming commands chart, timechart, stats, eventstats, and streamstats.

  • For more information about the stat command and syntax, see the "stats" command in the Search Reference.
  • For the list of stats functions, see "Statistical and charting functions" in the Search Reference.

About the stats commands and functions

The stats, streamstats, and eventstats commands each enable you to calculate summary statistics on the results of a search or the events retrieved from an index. The stats command works on the search results as a whole. The streamstats command calculates statistics for each event at the time the event is seen, in a streaming manner. The eventstats command calculates statistics on all search results and adds the aggregation inline to each event for which it is relevant. See more about the differences between these commands in the next section.

The chart command returns your results in a data structure that supports visualization as a chart (such as a column, line, area, and pie chart). You can decide what field is tracked on the x-axis of the chart. The timechart command returns your results formatted as a time-series chart, where your data is plotted against an x-axis that is always a time field. Read more about visualization features and options in the Visualization Reference of the Data Visualization Manual.

The stats, chart, and timechart commands (and their related commands eventstats and streamstats) are designed to work in conjunction with statistical functions. The list of statistical functions lets you count the occurrence of a field and calculate sums, averages, ranges, and so on, of the field values.

For the list of statistical functions and how they're used, see "Statistical and charting functions" in the Search Reference.

Stats, eventstats, and streamstats

The eventstats and streamstats commands are variations on the stats command.

The stats command works on the search results as a whole and returns only the fields that you specify. For example, the following search returns a table with two columns (and 10 rows).

sourcetype=access_* | head 10 | stats sum(bytes) as ASumOfBytes by clientip

The ASumOfBytes and clientip fields are the only fields that exist after the stats command. For example, the following search returns empty cells in the bytes column because it is not a result field.

sourcetype=access_* | head 10 | stats sum(bytes) as ASumOfBytes by clientip | table bytes, ASumOfBytes, clientip

To see more fields other than ASumOfBytes and clientip in the results, you need to include them in the stats command. Also, if you want to perform calculations on any of the original fields in your raw events, you need to do that before the stats command.

The eventstats command computes the same statistics as the stats command, but it also aggregates the results to the original raw data. When you run the following search, it returns an events list instead of a results table, because the eventstats command does not change the raw data.

sourcetype=access_* | head 10 | eventstats sum(bytes) as ASumOfBytes by clientip

You can use the table command to format the results as a table that displays the fields you want. Now, you can also view the values of bytes (or any of the original fields in your raw events) in your results.

sourcetype=access_* | head 10 | eventstats sum(bytes) as ASumOfBytes by clientip | table bytes, ASumOfBytes, clientip

The streamstats command also aggregates the calculated statistics to the original raw event, but it does this at the time the event is seen. To demonstrate this, include the _time field in the earlier search and use streamstats.

sourcetype=access_* | head 10 | sort _time | streamstats sum(bytes) as ASumOfBytes by clientip | table _time, clientip, bytes, ASumOfBytes

Instead of a total sum for each clientip (as returned by stats and eventstats), this search calculates a sum for each event based on the time that it is seen. The streamstats command is useful for reporting on events at a known time range.

Examples

Example 1

This example creates a chart of how many new users go online each hour of the day.

... | sort _time | streamstats dc(userid) as dcusers | delta dcusers as deltadcusers | timechart sum(deltadcusers)

The dc (or distinct_count) function returns a count of the unique values of userid and renames the resulting field dcusers.

If you don't rename the function, for example "dc(userid) as dcusers", the resulting calculation is automatically saved to the function call, such as "dc(userid)".

The delta command is used to find the difference between the current and previous dcusers value. Then, the sum of this delta is charted over time.

Example 2

This example calculates the median for a field, then charts the count of events where the field has a value less than the median.

... | eventstats median(bytes) as medbytes | eval snap=if(bytes>=medbytes, bytes, "smaller") | timechart count by snap

Eventstats is used to calculate the median for all the values of bytes from the previous search.

Example 3

This example calculates the standard deviation and variance of calculated fields.

sourcetype=log4j ERROR earliest=-7d@d latest=@d | eval warns=errorGroup+"-"+errorNum | stats count as Date_Warns_Count by date_mday,warns | stats stdev(Date_Warns_Count), var(Date_Warns_Count) by warns

This search returns errors from the last 7 days and creates the new field, warns, from extracted fields errorGroup and errorNum. The stats command is used twice. First, it calculates the daily count of warns for each day. Then, it calculates the standard deviation and variance of that count per warns.

Example 4

You can use the calculated fields as filter parameters for your search.

sourcetype=access_* | eval URILen = len(useragent) | eventstats avg(URILen) as AvgURILen, stdev(URILen) as StdDevURILen| where URILen > AvgURILen+(2*StdDevURILen) | chart count by URILen span=10 cont=true

In this example, eventstats is used to calculate the average and standard deviation of the URI lengths from useragent. Then, these numbers are used as filters for the retrieved events.

Use the stats command and functions (2024)

FAQs

What is the function of the stats command? ›

The SPL2 stats command calculates aggregate statistics, such as average, count, and sum, over the incoming search results set. This is similar to SQL aggregation. If the stats command is used without a BY clause, only one row is returned, which is the aggregation over the entire incoming result set.

What is the use of stats in Splunk? ›

The stats command is a fundamental Splunk command. It will perform any number of statistical functions on a field, which could be as simple as a count or average, or something more advanced like a percentile or standard deviation.

What is command in stats? ›

Use this command to provide summary statistics, optionally grouped by a field. The output for this query includes one field for each of the fields specified in the query, along with one field for each aggregation.

Which eval function would you use to round numerical values? ›

Mathematical Functions
FunctionDescriptionExample
round(X, Y)Rounds X to the nearest integer. Y is the precision to use, if omitted the default precision is zero. X can be a number, field or expression. Y is a numeric value to indicate the precision.... | eval n=round(1.4) Returns: 1 ... | eval n=round(1.5) Returns: 2
13 more rows

How to use stat command? ›

The 'stat' command in Linux is a powerful tool used to display detailed information about a file or file system. It is used with the syntax, stat [options] [file. txt or /path/to/directory] . In this example, we used the 'stat' command on 'myfile.

What is the stat function? ›

The stat() function shall obtain information about the named file and write it to the area pointed to by the buf argument. The path argument points to a pathname naming a file. Read, write, or execute permission of the named file is not required.

What are the functions of Splunk? ›

Splunk's software can be used to examine, monitor, and search for machine-generated big data through a browser-like interface. It makes searching for a particular piece of data quick and easy, and more importantly, does not require a database to store data as it uses indexes for storage.

What is stat tool used for? ›

The Statistical Training needs Assessment Tool, also known as STAT, is a tool developed for National Statistical Offices (NSO) to assess and analyze skills gaps of staff and strategically decide on how to prioritize and meet their training needs by using different types of informal and formal learning approaches.

What is the difference between stats and chart in Splunk? ›

In Summary

Use the stats command when you want to specify 3 or more fields in the BY clause. Use the chart command when you want to create results tables that show consolidated and summarized calculations. Use the chart command to create visualizations from the results table data.

What is a function command? ›

Function commands provide access to any system function from any screen and bypass the menu hierarchy.

What is command used for? ›

A command, in the context of technology and computing, is an instruction given by a user to a computer or software to perform a specific task. It can be a single word, a line of code, or a series of instructions that tell the computer what to do.

What is the command method? ›

Command Method is Behavioral Design Pattern that encapsulates a request as an object, thereby allowing for the parameterization of clients with different requests and the queuing or logging of requests.

What is the difference between stats and eval in Splunk? ›

stats operates on the whole set of events returned from the base search, and in your case you want to extract a single value from that set. eval creates a new field for all events returned in the search. Creating a new field called 'mostrecent' for all events is probably not what you intended.

What is the eval function in Splunk? ›

The Eval function calculates an expression and puts the resulting value into the record as a new field.

How do you use the eval function? ›

The Eval function evaluates the string expression and returns its value. For example, Eval("1 + 1") returns 2. If you pass to the Eval function a string that contains the name of a function, the Eval function returns the return value of the function.

What is the function of attribute command? ›

Using the ATTRIB command, you can change a file`s read/write attribute or set the archive attribute. If you use this command to specify a file as read-only, the file can be accessed, but not altered or deleted. If a file has an attribute of -R, it can be both read from or written to (it is referred to as read/write).

What is the function of stats? ›

Statistics is an important field because it helps us understand the general trends and patterns in a given data set. Statistics can be used for analysing data and drawing conclusions from it. It can also be used for making predictions about future events and behaviours.

What is the stats command in Minecraft? ›

The stats command allows "selectors" and "objectives" to be set (or cleared) for each of these command stats for specific blocks or entities. Selectors (for example, @e ) are stored exactly as entered, and don't get evaluated immediately.

What is the stats mode function? ›

mode(array, axis=0) function calculates the mode of the array elements along the specified axis of the array (list in python). Parameters : array : Input array or object having the elements to calculate the mode.

References

Top Articles
Using the Dividend Capture Strategy
Introducing Apple Intelligence for iPhone, iPad, and Mac
Ohio Houses With Land for Sale - 1,591 Properties
Was ist ein Crawler? | Finde es jetzt raus! | OMT-Lexikon
Chambersburg star athlete JJ Kelly makes his college decision, and he’s going DI
Mackenzie Rosman Leaked
Www.metaquest/Device Code
Fully Enclosed IP20 Interface Modules To Ensure Safety In Industrial Environment
Undergraduate Programs | Webster Vienna
Die Windows GDI+ (Teil 1)
Craigslist Free Stuff Appleton Wisconsin
Craigslist Dog Sitter
Comenity Credit Card Guide 2024: Things To Know And Alternatives
Qhc Learning
Power Outage Map Albany Ny
سریال رویای شیرین جوانی قسمت 338
Craigslist Free Stuff Santa Cruz
Extra Virgin Coconut Oil Walmart
Tamilrockers Movies 2023 Download
Best Forensic Pathology Careers + Salary Outlook | HealthGrad
The Ultimate Style Guide To Casual Dress Code For Women
Kp Nurse Scholars
Sadie Proposal Ideas
My Homework Lesson 11 Volume Of Composite Figures Answer Key
R&S Auto Lockridge Iowa
Greyson Alexander Thorn
Living Shard Calamity
Local Collector Buying Old Motorcycles Z1 KZ900 KZ 900 KZ1000 Kawasaki - wanted - by dealer - sale - craigslist
Lacey Costco Gas Price
R/Airforcerecruits
Radical Red Ability Pill
Giantbodybuilder.com
Umn Biology
Pioneer Library Overdrive
Storelink Afs
Workboy Kennel
Chs.mywork
How To Paint Dinos In Ark
Craigslist Free Manhattan
Topos De Bolos Engraçados
Ucsc Sip 2023 College Confidential
All-New Webkinz FAQ | WKN: Webkinz Newz
18006548818
Ucla Basketball Bruinzone
Dontrell Nelson - 2016 - Football - University of Memphis Athletics
Dagelijkse hooikoortsradar: deze pollen zitten nu in de lucht
Marcel Boom X
Dineren en overnachten in Boutique Hotel The Church in Arnhem - Priya Loves Food & Travel
Research Tome Neltharus
Lira Galore Age, Wikipedia, Height, Husband, Boyfriend, Family, Biography, Net Worth
Where Is Darla-Jean Stanton Now
Comenity/Banter
Latest Posts
Article information

Author: Terence Hammes MD

Last Updated:

Views: 5816

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.