Dashboards & Visualizations

How to display two single value total counts based on a single field?

jdepp
Path Finder

I am trying to display, in a panel, 2 single value total counts of messages based on a single field. The first should be the total messages while the second should the number of duplicates based on a single field.
For example, I thought the following would work:

source="/message.stats/tcp/10007"| stats count by id as Total | where count>1

This would display the total count of messages where there are duplicate values for the Id field.

source="/message.stats/tcp/10007"| stats count by id as Total

This should display the total count of messages. I am not sure how to combine the two. If not possible, I could just create 2 separate panels.

0 Karma
1 Solution

sundareshr
Legend

Try this

source="/message.stats/tcp/10007" | eventstats count as total | eventstats count as duplicates by id | stats count(eval(duplicates>1)) as no_duplicates values(total) as total | eval msg=no_duplicates." of ".total

You may want to change the count(eval(duplicates>1)) to sum(eval(duplicates>1))

View solution in original post

sundareshr
Legend

Try this

source="/message.stats/tcp/10007" | eventstats count as total | eventstats count as duplicates by id | stats count(eval(duplicates>1)) as no_duplicates values(total) as total | eval msg=no_duplicates." of ".total

You may want to change the count(eval(duplicates>1)) to sum(eval(duplicates>1))

jdepp
Path Finder

thanks a million; this worked for me

0 Karma

cmerriman
Super Champion
 source="/message.stats/tcp/10007"
|stats count by id 
|eval duplicateCount=if(count>1,count,null())
|addcoltotals
|eval singleValue=count+" total messages; "+duplicateCount+" total duplicate messages"
|search id="Total"
|fields singleValue

that should get you the total values for both the total and duplicates.
the stats is counting all events by id, then the eval only brings back the count if each id has more than one. then it's adding up the totals for each column and concatenating them together into a field called singleValue and only bringing back that value/field.

jdepp
Path Finder

Appreciate the response; when with the first solution.

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