Splunk Search

Compare today to yesterday's results

dackamen
Engager

Hi how should I modify my search to make it work?

host="javaserver1" source="/var/log/javastuff.log" earliest=-1d@d latest=-0d@d Sending failed | multikv | eval ReportKey="yesterday" | append [search host="javaserver1" source="/var/log/javastuff.log" earliest=-0d@d latest=now Sending failed | multikv | eval ReportKey="today"] |timechart span="1h" count by ReportKey

While today's results are displayed, yesterday's results are zero for every hour, then when yesterday's results begin displaying other values than zero, today's results are displayed all as zeroes.

Any solution to this?

Thank you

Tags (3)
1 Solution

carasso
Splunk Employee
Splunk Employee

Comparing week-over-week results used to a pain in Splunk, with complex date calculations. No more. Now there is a better way.

I wrote a convenient search command called "timewrap" that does it all, for arbitrary time periods.

... | timechart count span=1h | timewrap d 

That's it!

http://apps.splunk.com/app/1645/

View solution in original post

0 Karma

carasso
Splunk Employee
Splunk Employee

Comparing week-over-week results used to a pain in Splunk, with complex date calculations. No more. Now there is a better way.

I wrote a convenient search command called "timewrap" that does it all, for arbitrary time periods.

... | timechart count span=1h | timewrap d 

That's it!

http://apps.splunk.com/app/1645/

0 Karma

lguinn2
Legend

Another alternative:

host="javaserver1" source="/var/log/javastuff.log" earliest=-1d@d latest=-0d@d Sending failed | multikv | eval ReportKey="yesterday" | 
eval _time=relative_time(_time,"+1d") |
append [search host="javaserver1" source="/var/log/javastuff.log" earliest=-0d@d latest=now Sending failed | multikv | eval ReportKey="today"] |
timechart span="1h" count by ReportKey

Notice that this is the same as your original search BUT I added one day to the timestamp. This forces the data from yesterday to plot over the same time period as the data from today.

The other solution should be faster in most cases, but this will be more flexible when you really want to use a timechart.

lguinn2
Legend

The append command adds today's results as separate events following yesterday's. Then timechart sums the events based on _time, so the two series will not overlap. Try this instead

host="javaserver1" source="/var/log/javastuff.log" earliest=-1d@d latest=now Sending failed |
multikv | 
eval hour = strftime(_time,"%H") |
eval reportKey = if(_time<relative_time(now(), "-0d@d"),"yesterday","today") |
chart count over hour by reportKey

vickyvishwa
Explorer

Thank you.
How do we compare today's hour and previous week same day/hour with this query ? Can u suggest ?

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...