Splunk Search

How to get the last 15 days of logs relative to the latest event, not to now?

Javo222
Path Finder

I can't find the correct syntax to search the last 15 days of logs, relative to the latest entry. My current search is as follow:

source="test.log" CPU_Usage=* | timechart span=20m max(CPU_Usage)

If I change the time range to "latest 15 days", it's relative to NOW, not the latest event.

Tags (2)
1 Solution

aljohnson_splun
Splunk Employee
Splunk Employee

I don't know if this the best way to do it, but it is one way.

source="test.log" CPU_Usage=*
| join [| metadata type=sources source="test.log"| stats max(lastTime) as latest]
|  timechart span=20m max(CPU_Usage)
0 Karma

Javo222
Path Finder

I get "No results found" when using these lines. Do I need to change anything? The query from Chanfoli returns several hundred results (as it should).

0 Karma

chanfoli
Builder

Javo222
Path Finder

That work with a few changes.

source="*test.log*" CPU_Usage=*  [ search CPU_Usage=* | head 1 | eval earliest=relative_time(_time,"-15d") | eval latest=_time | fields earliest, latest | format "(" "(" "" ")" "OR" ")"  ] | timechart span=20m max(CPU_Usage)
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...