Splunk Search

How to display a column of percentages using one entry as the max

allanmb
Engager

I have a table that shows the count of messages in my log. I want to be able to display the percentage of these using one entry as the number I care about. First, here is the search I am using:

<search> | eval msg=<something> | stats count by msg | sort - count

This gives something like this:

  • msg, count NumInterestingEntries, 10000 LableA, 8888 LableB, 6003 LableC, 4987

I would like to have a new column with the percentage based on 'out of the NumInterstingEntries' value. like this:

  • msg, count NumInterestingEntries, 10000, 100% LableA, 8888, 88.88% LableB, 6003, 60.03% LableC, 4987, 49.87%

How would I achieve this? I tried adding

 | eventstats count as "totalCount" | eventstats count as "choiceCount" by msg | eval percent=(choiceCount/totalCount)*100 | stats values(percent) by msg | sort - values(percent)

but this adds the column up to make totalCount. I cant seem to select the cell I want to use instead of totalCount
Thanks

0 Karma
1 Solution

maciep
Champion

what about something like this?

 <search> | eval msg=<something> | stats count by msg | eventstats max(count) as max | eval percent = tostring((count/max)*100)."%" | fields - max

View solution in original post

0 Karma

maciep
Champion

what about something like this?

 <search> | eval msg=<something> | stats count by msg | eventstats max(count) as max | eval percent = tostring((count/max)*100)."%" | fields - max
0 Karma

allanmb
Engager

Perfect, thanks 🙂 I just added the following on the end to make it sorted

| sort - count
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...