Splunk Search

How to aggregate a percentage of a total before another search?

faramarz
Path Finder

Hey! I am trying to figure out how to aggregate a percentage of the total before another search like this:

eventName = pageLoad | eventstats count as Total | search currentPage "\/brands\/" | stats count(currentPage) as counter by currentPage | eval percent = counter/Total

The percent field is always empty when I try to display it using table, and the variable Total seems to disappear once I get past the stats command. What should I do to preserve that total? Thanks!

Best,
F

0 Karma
1 Solution

somesoni2
Revered Legend

The stats will remove all other fields which are not specified. Try something like this

eventName = pageLoad | eventstats count as Total | search currentPage "\/brands\/" | stats count(currentPage) as counter max(Total) as Total by currentPage | eval percent = counter/Total

Since Total field is generated as same value for all events (eventstats without by clause), you can use any aggregation function of splunk to get it (min, max, values, first, last).

View solution in original post

somesoni2
Revered Legend

The stats will remove all other fields which are not specified. Try something like this

eventName = pageLoad | eventstats count as Total | search currentPage "\/brands\/" | stats count(currentPage) as counter max(Total) as Total by currentPage | eval percent = counter/Total

Since Total field is generated as same value for all events (eventstats without by clause), you can use any aggregation function of splunk to get it (min, max, values, first, last).

faramarz
Path Finder

Amazing. Thanks so much 🙂

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 ...