Splunk Search

How do I select a time frame for events?

lmzheng
Explorer

For the following search, I want to display the earliest and latest events within a duration of a year. However, I want the Error Counts to be displayed with a duration of only a week. I read about spans, but it doesn't seem to be producing the results I want.

| search EventType=Errors
| eval ErrorMessage=Server+": "+Application+": " +ErrorMessage
| stats earliest(_time) as Earliest, latest(_time) as Latest, count as "Error Count" by ErrorMessage
| convert ctime(Earliest), ctime(Latest)
| sort - "Error Count"
| head 10

Thank you!
Lee

0 Karma

solarboyz1
Builder

Use use the eval command in stats to get a count of the events whose timestamp are occur within the last week:

| search EventType=Errors earliest=-1y
| eval ErrorMessage=Server+": "+Application+": " +ErrorMessage
| stats earliest(_time) as Earliest, latest(_time) as Latest, count as "Error Count YTD", count(eval(_time>(now()-604800))) as "Error Count WTD" by ErrorMessage
| convert ctime(Earliest), ctime(Latest)
| sort - "Error Count WTD"
| head 10
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...