Splunk Search

chart count for comparison

selvam_sekar
Path Finder

Hi,

I have the below SPL and I am not able to get the expected results. Please could you help?

if i use stats count by - then i'm not getting the expected result as below.

SPL:

basesearch earliest=@d latest=now
| append
[ search earliest=-1d@d latest=-1d]
| eval Consumer = case(match(File_Name,"^ABC"), "Down", match(File_Name,"^csd"),"UP", match(File_Name,"^CSD"),"UP",1==1,"Others")
| eval Day=if(_time<relative_time(now(),"@d"),"Yesterday","Today")
| eval percentage_variance=abs(round(((Yesterday-Today)/Yesterday)*100,2))
| table Name Consumer Today Yesterday percentage_variance

Expected Result:

NameConsumerTodayYesterdaypercentage_variance
TENUP10100.0%
Labels (4)
Tags (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Assuming these are counts, you need to get values for Today and Yesterday into the same event in the pipeline. Try something like this

basesearch earliest=@d latest=now
| append
[ search earliest=-1d@d latest=-1d]
| eval Consumer = case(match(File_Name,"^ABC"), "Down", match(File_Name,"^csd"),"UP", match(File_Name,"^CSD"),"UP",1==1,"Others")
| eval Day=if(_time<relative_time(now(),"@d"),"Yesterday","Today")
| stats count by Name Consumer Day
| eval {Day}=count
| fields - Day
| stats values(Today) as Today values(Yesterday) as Yesterday by Name Consumer
| eval percentage_variance=abs(round(((Yesterday-Today)/Yesterday)*100,2))
| table Name Consumer Today Yesterday percentage_variance

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming these are counts, you need to get values for Today and Yesterday into the same event in the pipeline. Try something like this

basesearch earliest=@d latest=now
| append
[ search earliest=-1d@d latest=-1d]
| eval Consumer = case(match(File_Name,"^ABC"), "Down", match(File_Name,"^csd"),"UP", match(File_Name,"^CSD"),"UP",1==1,"Others")
| eval Day=if(_time<relative_time(now(),"@d"),"Yesterday","Today")
| stats count by Name Consumer Day
| eval {Day}=count
| fields - Day
| stats values(Today) as Today values(Yesterday) as Yesterday by Name Consumer
| eval percentage_variance=abs(round(((Yesterday-Today)/Yesterday)*100,2))
| table Name Consumer Today Yesterday percentage_variance
0 Karma

selvam_sekar
Path Finder

Many Thanks @ITWhisperer . In this SPL Logic how do we ignore the weekend dataand bring only the last working day count for yesterday ? is it possible ?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Change this line so that it takes into account what the previous day is

[ search earliest=-1d@d latest=-1d]
0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

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