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!

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...