Splunk Enterprise

How to fetch time in splunk logs for events with particular context

ksuyash
Engager
6/29/22
4:58:14.526 PM
 
2022-06-29 17:58:14.526 [Task1] INFO Task1 - Published Task1 received  id 101

 

6/29/22
4:59:14.526 PM
 
2022-06-29 17:58:14.526 [Task1] INFO Task1 - Published Task1 done  id 101


I'm trying  to fetch time for both the events (when it is received and when the task is done)  and calculate the difference between them in form of table 

I tried 
index=source "Published Task 1"
| rex "id" (?<ID>\d+) 
| table  ID start_time End_time difference _time

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

What's lacking in that query are the fields other than "ID".  You can, however, use stats and eval to get them.

index=source "Published Task 1"
| rex "id" (?<ID>\d+) 
| stats min(_time) as start_time, max(_time) as End_time by ID
| eval difference_time = End_time - start_time
| table  ID start_time End_time difference_time

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

What's lacking in that query are the fields other than "ID".  You can, however, use stats and eval to get them.

index=source "Published Task 1"
| rex "id" (?<ID>\d+) 
| stats min(_time) as start_time, max(_time) as End_time by ID
| eval difference_time = End_time - start_time
| table  ID start_time End_time difference_time

 

---
If this reply helps you, Karma would be appreciated.

ksuyash
Engager

It was really helpful 
Thank you so much 
I'm getting time in Unix format 
1656483082.160
Any easy way to convert it

0 Karma
Get Updates on the Splunk Community!

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

Dive into our sizzling summer lineup for July and August Community Office Hours and Tech Talks. Scroll down to ...

Edge Processor Scaling, Energy & Manufacturing Use Cases, and More New Articles on ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Get More Out of Your Security Practice With a SIEM

Get More Out of Your Security Practice With a SIEMWednesday, July 31, 2024  |  11AM PT / 2PM ETREGISTER ...