Splunk Search

How to edit my current search to find the difference between yesterday's count and today's count?

nivethainspire_
Explorer

I need to add a column stating the difference in count (today - yesterday). How can I write this search?

Existing search:

index=sample | eval Segments = if(like(Segments ,"%om%"), "omg", "DTDC")|search Segments=Omg Class=Server OR Name=Server OR Class=""|stats sum(evn) as evn sum(eval(if(Flags=="NULL" AND blank!="NULL",evn, 0))) as "OSScore" 

The above serach runs for today's timestamp.

0 Karma

woodcock
Esteemed Legend

Try running this for the last 2 days:

index=sample | eval Segments = if(like(Segments ,"%om%"), "omg", "DTDC")
| search Segments=Omg Class=Server OR Name=Server OR Class=""
| bucket _time span=1d
| stats sum(evn) AS evn sum(OSScore) AS OSScore BY _time
| addtotals row=f col=t labelfield=_time *
| eventstats first(*) AS today_* last(*) as yesterday_*
| foreach yesterday_* [eval <<FIELD>> = <<FIELD>> - today_<<MATCHSEG1>>]
| tail 1
0 Karma

nivethainspire_
Explorer

what change Should I make to get the difference for yesterday's and "Day before" data.

0 Karma

sundareshr
Legend

Try this

index=sample earliest=-1d@d 
| eval Segments = if(like(Segments ,"%om%"), "omg", "DTDC") 
| search Segments=Omg Class=Server OR Name=Server OR Class="" 
| eval when=if(_time<relative_time(now(), "@d"), "Yesterday", "Today") 
| stats sum(evn) as evn sum(eval(if(Flags=="NULL" AND blank!="NULL",evn, 0))) as "OSScore" by when 
| untable when stat values 
| chart values(values) as values over stat by when 
| eval diff=Yesterday-Today
0 Karma

niketn
Legend

Try the following:

index=sample earliest=-1d@d latest=now | eval Segments = if(like(Segments ,"%om%"), "omg", "DTDC")|search Segments=Omg Class=Server OR Name=Server OR Class=""|stats sum(evn) as evn sum(eval(if(Flags=="NULL" AND blank!="NULL",evn, 0))) as "OSScore" by date_mday | delta OSScore as Difference

Delta command gives a difference between nearby numeric field results. It is inverse of accum command. If you take out earliest & latest time, delta command will perform difference for each subsequent result.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

niketn
Legend

@nivethainspire_07 If your search query in the question is what you need you can modify the earliest and latest to time range you want and delta will give you difference between each consecutive rows.

Following compares last 7 days with difference of OSScore for each consecutive day:

index=sample earliest=-7d@d latest=now | eval Segments = if(like(Segments ,"%om%"), "omg", "DTDC")|search Segments=Omg Class=Server OR Name=Server OR Class=""|stats sum(evn) as evn sum(eval(if(Flags=="NULL" AND blank!="NULL",evn, 0))) as "OSScore" by date_mday | delta OSScore as Difference

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...