Splunk Search

how to find the earliest and latest event in an index?

hiddenkirby
Contributor

I simply looking for the fist event in an index and the last... to determine how long it took to index x data.

any suggestions? i couldn't seem to figure out that query.

Tags (3)
1 Solution

ziegfried
Influencer

Do you mean the time when the event has been indexed? Then the query would be:

index=<your_index> | stats min(_indextime) as min_indextime max(_indextime) as max_indextime | convert ctime(min_indextime) ctime(max_indextime)

View solution in original post

claudio_manig
Communicator

I know thats an old post but i wanted to share a way more efficient solution to get latest timestamp by each index in a "metadata" manor:

| rest /services/data/indexes
| stats max(maxTime) by title

 

Hop that helps others-

Cheers 

khourihan_splun
Splunk Employee
Splunk Employee

Try this
| metadata index=main type=hosts | stats min(firstTime) max(lastTime) by host

0 Karma

joy76
Path Finder

look at
Settings > DATA > Indexes menu.
There are earliest and last event time by Index.

0 Karma

ziegfried
Influencer

Do you mean the time when the event has been indexed? Then the query would be:

index=<your_index> | stats min(_indextime) as min_indextime max(_indextime) as max_indextime | convert ctime(min_indextime) ctime(max_indextime)

hiddenkirby
Contributor

i do have DATATIME_CONFIG = current.

0 Karma

hiddenkirby
Contributor

i ended up w/ max(_time) and min(_time) .. convert was very helpful. thank you both.

0 Karma

ziegfried
Influencer

_time and _indextime are only equal when you use DATETIME_CONFIG = current in your props config of if no timestamp was detected in the event.

0 Karma

ziegfried
Influencer

_indextime is always the time when the event has been index. _time can be a different time, for example when the time found within an event is used

0 Karma

hiddenkirby
Contributor

whats the difference between _indextime and _time?

0 Karma

Lowell
Super Champion

You can look at the index event times using something like this:

| metadata index=main type=hosts | stats min(firstTime) max(lastTime)

Or, to examine individual events, you can compare the _time and _indextime fields:

 index=main | eval lag=_indextime-_time | stats avg(lag) ...

Do either of these help?

damode
Motivator

Hi Lowell,

When I try this command, | metadata index=main type=hosts | stats min(firstTime) max(lastTime), all I get is two columns, min(firstTime) max(lastTime) with time in seconds.

Can you please advise where I am getting it wrong ?
Thanks.
Dev

0 Karma

hiddenkirby
Contributor

This was helpful.

0 Karma
Get Updates on the Splunk Community!

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...