Splunk Search

How to customize stats using simple math?

flow2k
Explorer

If I wanted a count of all the events in all my indices, I can just do:
index=* | stats count, which just returns a single number in a single row with this value.

But say I wanted to customize the stats function - say I want to add 2 to the count returned:
index=* | stats count+2 is invalid.

How can I customize an aggregate statistics function with simple math operations?

0 Karma

damiensurat
Contributor

index=* | stats count AS count| eval count = count + 2

skoelpin
SplunkTrust
SplunkTrust

Try this

| metasearch index=*
| stats count 
| eval count='count'+2

You need to use an eval to do basic mathematical calculations

Metasearch will look at your index time fields and search 10x faster than doing index=*

skoelpin
SplunkTrust
SplunkTrust

Please accept the answer if this helped you

flow2k
Explorer

This answer is very helpful and I've upvoted the answer - thank you! However, as it stands, both answers are equally valid, so I'm leaving it to the community to vote on them.

0 Karma

davpx
Communicator

I downvoted this post because refusing to accept a correct answer leaves unanswered spam on the board.

skoelpin
SplunkTrust
SplunkTrust

In the Splunk community, users accept answers that helped them solve their problem. This signals a correct answer for users who may look at this in the future. Since both answers are valid, it's fair to accept the one that helped more and/or who answered first, which in this case is this one.

Top contributors on this forum would also be reluctant to answer your future questions if your known not to accept the correct answers

Get Updates on the Splunk Community!

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...

Get ready to show some Splunk Certification swagger at .conf24!

Dive into the deep end of data by earning a Splunk Certification at .conf24. We're enticing you again this ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Now On-Demand Join us to learn more about how you can leverage Service Level Objectives (SLOs) and the new ...