Splunk Search

Why use eventstats and stats together?

luna
Explorer

Hello,

I have seen eventstats and stats used together, but I’m not clear on why and when the use of the mentioned would need to be used.

can you explain why use eventstats and stats together and provide an example?

Labels (1)
0 Karma

tscroggins
Influencer

In a similar vein to @ITWhisperer's answer, I sometimes combine them for filtering, although this example is contrived:

| stats count by foo
| eventstats max(count) as mode
| where count==mode

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

eventstats adds fields to the events and preserves the existing fields

stats replaces the events with calculated fields

For example, let's say you wanted to chart percentage of events from each host per day

 

 ... | bin span=1d _time
| stats count BY _time host
| eventstats sum(count) as total by _time
| eval percent = count / total
| chart values(percent) by _time host

 

stats does the counting by time and host

eventstats calculates the daily total

eval calculates the daily percentage for each host

0 Karma
Get Updates on the Splunk Community!

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

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

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...