Splunk Search

How to find the earliest event in a query that can search in an index?

xindeNokia
Path Finder

My understanding is Splunk will purge old data in an index when the disk limit is reached.
What is the easy/fast way to find out the earliest available event in an index?

Thanks in advance

0 Karma
1 Solution

niketn
Legend

@xindeNokia you can use metadata specific commands like tstats, metadata or dbinspect depending on your use case.
Following are some run anywhere examples based on Splunk's _internal index. Change index name as per your requirement.

tstats:

| tstats earliest(_time) as earliestTime latest(_time) as latestTime count as eventCount where index=_internal
| fieldformat earliestTime=strftime(earliestTime,"%Y/%m/%d %H:%M:%S")
| fieldformat latestTime=strftime(latestTime,"%Y/%m/%d %H:%M:%S")

metadata:

| metadata type=sourcetypes index=_internal
| fieldformat firstTime=strftime(firstTime,"%Y/%m/%d %H:%M:%S")
| fieldformat lastTime=strftime(lastTime,"%Y/%m/%d %H:%M:%S")

PS: stats min(firstTime) can be added to get earliest time across grouped default field in this case sourcetypes

dbinspect:

| dbinspect index=_internal
| fieldformat startEpoch=strftime(startEpoch,"%Y/%m/%d %H:%M:%S")
| fieldformat endEpoch=strftime(endEpoch,"%Y/%m/%d %H:%M:%S")
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

niketn
Legend

@xindeNokia you can use metadata specific commands like tstats, metadata or dbinspect depending on your use case.
Following are some run anywhere examples based on Splunk's _internal index. Change index name as per your requirement.

tstats:

| tstats earliest(_time) as earliestTime latest(_time) as latestTime count as eventCount where index=_internal
| fieldformat earliestTime=strftime(earliestTime,"%Y/%m/%d %H:%M:%S")
| fieldformat latestTime=strftime(latestTime,"%Y/%m/%d %H:%M:%S")

metadata:

| metadata type=sourcetypes index=_internal
| fieldformat firstTime=strftime(firstTime,"%Y/%m/%d %H:%M:%S")
| fieldformat lastTime=strftime(lastTime,"%Y/%m/%d %H:%M:%S")

PS: stats min(firstTime) can be added to get earliest time across grouped default field in this case sourcetypes

dbinspect:

| dbinspect index=_internal
| fieldformat startEpoch=strftime(startEpoch,"%Y/%m/%d %H:%M:%S")
| fieldformat endEpoch=strftime(endEpoch,"%Y/%m/%d %H:%M:%S")
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...