Use stats with eval expressions and functions (2024)

You can embed eval expressions and functions within any of the stats functions. This is a shorthand method for creating a search without using the eval command separately from the stats command.

For example, the following search uses the eval command to filter for a specific error code. Then the stats function is used to count the distinct IP addresses.

status=* | eval dc_ip_errors=if(status=404,clientip,NULL()) | stats dc(dc_ip_errors)

As an alternative, you can embed an eval expression using eval functions in a stats function directly to return the same results. For example:

status=* | stats dc(eval(if(status=404, clientip, NULL()))) AS dc_ip_errors

Use eval expressions to count the different types of requests against each Web server

This example uses the sample data from the Search Tutorial but should work with any format of Apache web access log. To try this example on your own Splunk instance, you must download the sample data and follow the instructions to get the tutorial data into Splunk. Use the time range All time when you run the search.

Run the following search to use the stats command to determine the number of different page requests, GET and POST, that occurred for each Web server.

sourcetype=access_* | stats count(eval(method="GET")) AS GET, count(eval(method="POST")) AS POST BY host

This example uses eval expressions to specify the different field values for the stats command to count.

  • The first clause uses the count() function to count the Web access events that contain the method field value GET. Then, using the AS keyword, the field that represents these results is renamed GET.
  • The second clause does the same for POST events.
  • The counts of both types of events are then separated by the web server, using the BY clause with the host field.

The results appear on the Statistics tab and look something like this:

hostGETPOST
www184315197
www280974815
www383384654

Use eval expressions to categorize and count fields

This example uses sample email data. You should be able to run this search on any email data by replacing the sourcetype=cisco:esa with the sourcetype value and the mailfrom field with email address field name in your data. For example, the email might be To, From, or Cc).

Find out how much of the email in your organization comes from .com, .net, .org or other top level domains.

The eval command in this search contains two expressions, separated by a comma.

sourcetype="cisco:esa" mailfrom=* | eval accountname=split(mailfrom,"@"), from_domain=mvindex(accountname,-1) | stats count(eval(match(from_domain, "[^\n\r\s]+\.com"))) AS ".com", count(eval(match(from_domain, "[^\n\r\s]+\.net"))) AS ".net", count(eval(match(from_domain, "[^\n\r\s]+\.org"))) AS ".org", count(eval(NOT match(from_domain, "[^\n\r\s]+\.(com|net|org)"))) AS "other"

  • The first part of this search uses the eval command to break up the email address in the mailfrom field. The from_domain is defined as the portion of the mailfrom field after the @ symbol.
    • The split() function is used to break the mailfrom field into a multivalue field called accountname. The first value of accountname is everything before the "@" symbol, and the second value is everything after.
    • The mvindex() function is used to set from_domain to the second value in the multivalue field accountname.
  • The results are then piped into the stats command. The stats count() function is used to count the results of the eval expression.
  • Theeval eexpression uses the match() function to compare the from_domain to a regular expression that looks for the different suffixes in the domain. If the value of from_domain matches the regular expression, the count is updated for each suffix, .com, .net, and .org. Other domain suffixes are counted as other.

The results appear on the Statistics tab and look something like this:

.com.net.orgother
4246989003543

See also

Commands
eval command in the Search Reference
Related information
Statistical and charting functions in the Search Reference
Evaluation functions in the Search Reference
About evaluating and manipulating fields

Last modified on 11 May, 2020

Use the stats command and functionsAdd sparklines to search results

This documentation applies to the following versions of Splunk® Enterprise: 7.0.0, 7.0.2, 7.0.3, 7.0.4, 7.0.5, 7.0.6, 7.0.7, 7.0.8, 7.0.9, 7.0.10, 7.0.11, 7.0.13, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.1.6, 7.1.7, 7.1.8, 7.1.9, 7.1.10, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.2.8, 7.2.9, 7.2.10, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.3.6, 7.3.7, 7.3.8, 7.3.9, 8.0.0, 8.0.1, 8.0.2, 8.0.3, 8.0.4, 8.0.5, 8.0.6, 8.0.7, 8.0.9, 8.0.10, 7.0.1, 8.0.8, 8.1.2, 8.1.3, 8.1.4, 8.1.5, 8.1.6, 8.1.7, 8.1.8, 8.1.9, 8.1.11, 8.1.12, 8.1.13, 8.1.14, 8.2.0, 8.2.1, 8.2.2, 8.2.3, 8.2.4, 8.2.5, 8.2.6, 8.2.7, 8.2.8, 8.2.9, 8.2.10, 8.2.11, 8.2.12, 9.0.0, 9.0.1, 9.0.2, 9.0.3, 9.0.4, 9.0.5, 9.0.6, 9.0.7, 9.0.8, 9.0.9, 9.0.10, 9.1.0, 9.1.1, 9.1.2, 9.1.3, 9.1.4, 9.1.5, 9.2.0, 9.2.1, 9.2.2, 9.3.0, 8.1.0, 8.1.1, 8.1.10

Use stats with eval expressions and functions (2024)

FAQs

What is the difference between stats and eval? ›

Difference between stats and eval commands

The command Stats measures statistics in your events based on fields. The eval command uses existing fields and an optional expression to construct new fields in your events.

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 are the common functions used with the stats command? ›

Statistical functions (reference)
FunctionDescription
TREND functionReturns values along a linear trend
TRIMMEAN functionReturns the mean of the interior of a data set
VAR.P functionCalculates variance based on the entire population
VAR.S functionEstimates variance based on a sample
107 more rows

What is the stats command in SPL? ›

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 purpose of eval? ›

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 role of statistics in evaluation? ›

Statistical methods are essential in monitoring and evaluation (M&E) to analyze program performance and impact. They provide a rigorous and objective approach to data analysis and can help identify patterns, trends, and associations between program inputs, activities, outputs, and outcomes.

What do you use stats for? ›

Statistics is used to conduct research, evaluate outcomes, develop critical thinking, and make informed decisions about a set of data. Statistics can be used to inquire about almost any field of study to investigate why things happen, when they occur, and whether reoccurrence is predictable.

What is eval in Splunk? ›

eval allows you to take search results and perform all sorts of, well, evaluations of the data. The eval command can help with all this and more: Conditional functions, like if, case and match. Mathematical functions, like round and square root. Date and time functions.

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 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 use of stats command? ›

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.

What are the most commonly used statistical functions? ›

Here is list of basic statistical functions in excel given below:
  • Count Function.
  • Counta Function.
  • Countblank Function.
  • Countifs Function.
Aug 14, 2023

What are stats in Splunk? ›

The stats command is used 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 and returns only the fields that you specify. Each time you invoke the stats command, you can use one or more functions.

How do you 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 in Linux? ›

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 is the difference between stats and statistics? ›

A statistic is the descriptor of a set of sample data. Statistics is the broader concept of the process of designing, comparing, interpreting, and analyzing data.

What is the difference between test and eval? ›

In case you are curious, here are some definitions:

A test or quiz is used to examine someone's knowledge of something to determine what he or she knows or has learned. Testing measures the level of skill or knowledge that has been reached. Evaluation is the process of making judgments based on criteria and evidence.

What is the difference between assessment and eval? ›

Assessment is primarily formative in nature, providing ongoing feedback, while evaluation is primarily summative, providing an overall judgment. Assessment is often individual-focused, aiming to improve learning and performance, whereas evaluation is system-focused, aiming to improve educational programs and policies.

What is the difference between stats and EVs? ›

Stat Experience and EVs are indeed similar in the way they work. However, the way they are calculated are different. Stat Exp is calculated for every battle your pokemon takes part in (like EVs). However, Stat Exp gained is based on the defeated Pokemon's Base Stats (That's all of the stats, rather than just 1 or 2).

Top Articles
Wharton Dental Of Piqua Photos
Tsuki Odyssey Fish Guide
NYT Mini Crossword today: puzzle answers for Tuesday, September 17 | Digital Trends
Toyota Campers For Sale Craigslist
Txtvrfy Sheridan Wy
Osrs But Damage
Deshret's Spirit
Geometry Escape Challenge A Answer Key
OnTrigger Enter, Exit ...
Daniela Antury Telegram
Delectable Birthday Dyes
Helloid Worthington Login
Calmspirits Clapper
Midlife Crisis F95Zone
Leader Times Obituaries Liberal Ks
St Maries Idaho Craigslist
Plan Z - Nazi Shipbuilding Plans
Healthier Homes | Coronavirus Protocol | Stanley Steemer - Stanley Steemer | The Steem Team
Tyrone Unblocked Games Bitlife
Rs3 Ushabti
Silky Jet Water Flosser
Craigslist Wilkes Barre Pa Pets
Used Patio Furniture - Craigslist
Victory for Belron® company Carglass® Germany and ATU as European Court of Justice defends a fair and level playing field in the automotive aftermarket
Malluvilla In Malayalam Movies Download
Lcsc Skyward
R/Mp5
Stubhub Elton John Dodger Stadium
Plasma Donation Racine Wi
DIY Building Plans for a Picnic Table
Pfcu Chestnut Street
Flaky Fish Meat Rdr2
Adecco Check Stubs
Tributes flow for Soundgarden singer Chris Cornell as cause of death revealed
Netherforged Lavaproof Boots
Justin Mckenzie Phillip Bryant
Junior / medior handhaver openbare ruimte (BOA) - Gemeente Leiden
Blue Beetle Movie Tickets and Showtimes Near Me | Regal
Delaware judge sets Twitter, Elon Musk trial for October
Mohave County Jobs Craigslist
Craigslist Ludington Michigan
The Banshees Of Inisherin Showtimes Near Reading Cinemas Town Square
Dogs Craiglist
More News, Rumors and Opinions Tuesday PM 7-9-2024 — Dinar Recaps
Gfs Ordering Online
Who Is Responsible for Writing Obituaries After Death? | Pottstown Funeral Home & Crematory
Dwc Qme Database
1Tamilmv.kids
Joe Bartosik Ms
Otter Bustr
Ubg98.Github.io Unblocked
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 6385

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.