Splunk Search

To count the filed with different time range

parthiban
Path Finder

Hi 

I have events that having multiple countries... I want to count the country field and with different time range. It is need to sort by highest country to lowest.

EX   Country         Last 24h     Last 30 days     Last 90 days

           US                       10                   50                            100

           Aus                       8                     35                              80

I need query kindly assist me.


Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| bin _time span=1d
| stats count(eval(_time>=relative_time(now(),"@d-1d"))) as 24hCount  count(eval(_time>=relative_time(now(),"@d-30d"))) as 30dCount count(eval(_time>=relative_time(now(),"@d-90d"))) as 90dCount by Country

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| bin _time span=1d
| stats count(eval(_time>=relative_time(now(),"@d-1d"))) as 24hCount  count(eval(_time>=relative_time(now(),"@d-30d"))) as 30dCount count(eval(_time>=relative_time(now(),"@d-90d"))) as 90dCount by Country

parthiban
Path Finder

Hi @ITWhisperer 
The query is working, but the result is not as expected. The timeframe is also not returning the correct results. I need the highest count for the past 30 days, with the country having the highest count appearing first, followed by other countries in descending order.

The below is the current result.
parthiban_0-1728403827452.png

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

So how would this look? You can only sort in an particular order of precedence i.e. 30days first then if they are equal, 90days, then if still equal 1 day, you know that right?

0 Karma

parthiban
Path Finder

Hi @ITWhisperer 

I made small changes in given query. It is working as expected.. Thanks for your support

0 Karma

PickleRick
SplunkTrust
SplunkTrust
0 Karma
Get Updates on the Splunk Community!

Now Available: Cisco Talos Threat Intelligence Integrations for Splunk Security Cloud ...

At .conf24, we shared that we were in the process of integrating Cisco Talos threat intelligence into Splunk ...

Preparing your Splunk Environment for OpenSSL3

The Splunk platform will transition to OpenSSL version 3 in a future release. Actions are required to prepare ...

Easily Improve Agent Saturation with the Splunk Add-on for OpenTelemetry Collector

Agent Saturation What and Whys In application performance monitoring, saturation is defined as the total load ...