Getting Data In

Timediffrence between two different events

venksplunk1
Loves-to-Learn

Hi All,

I have two different search criteria & query. First search criteria/query will produce the start time for event 1 and second search criteria/query will be provide End time for event1. Need to calculate the duration between Start and End time using Splunk.

Labels (1)
0 Karma

venksplunk1
Loves-to-Learn

Time Stamp Format for Start and End Time as follows: 2021-08-24T04:31:32.245+00:00

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

for individual event you can try this one:

index=XX cf_org_name=YY event_type=LogMessage cf_app_name="*-Envtname*" 
| spath "msg.message" 
| search "msg.message"="*ProductID*" 
| spath "msg.message" 
| search "msg.message"!="*ACTIVITY.LOG.IMPORTS*" 
| spath "msg.level" 
| spath cf_app_name 
| search cf_app_name="*Servicename*" 
| spath "msg.message" 
| search "msg.message"="*Request Initiated*" OR "msg.message"="*Request Fulfilled*"
| rename msg.@timestamp as EventStartTime,  msg.@timestamp as EventEndTIme
| eval sTime = strptime(EventStartTime, "%Y-%m-%dT%H:%M:%S.%3Q%:z"), eTime = strptime(EventEndTime, "%Y-%m-%dT%H:%M:%S.%3Q%:z")
| eval dTime = eTime - sTime, duration = tostring(dTime, "duration")
| table cf_app_name, EventStartTime, EventEndTime, duration, msg.message

For several events it could be better to use streamstats etc?

r. Ismo 

0 Karma

venksplunk1
Loves-to-Learn

Thanks for your reply.

My First query as follows: It will capture the EventStartTime

index=XX cf_org_name=YY event_type=LogMessage cf_app_name="*-Envtname*" | spath "msg.message" | search "msg.message"="*ProductID*" | spath "msg.message" | search "msg.message"!="*ACTIVITY.LOG.IMPORTS*" | spath "msg.level" | spath cf_app_name | search cf_app_name="*Servicename*" | spath "msg.message" | search "msg.message"="*Request Initiated*"  rename msg.@timestamp as EventStartTime |table cf_app_name,   EventStartTimemsg.message

 

My Second query as follows: It will capture the EventEndTime

index=XX cf_org_name=YY event_type=LogMessage cf_app_name="*-Envtname*" | spath "msg.message" | search "msg.message"="*ProductID*" | spath "msg.message" | search "msg.message"!="*ACTIVITY.LOG.IMPORTS*" | spath "msg.level" | spath cf_app_name | search cf_app_name="*Servicename*" | spath "msg.message" | search "msg.message"="*Request Fulfilled*"  rename msg.@timestamp as EventEndTIme |table cf_app_name,   EventEndTimemsg.message

 

As of now, I have executed my first and second queries sequentially and able to capture the start and end time. Need to capture the Start and End time in parallel and measure the difference between Start and End time. Duration=EventEndTime-EventStartTIme.

Would it be possible to help me here? Let me know if you are need of any additional details.

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

there are some different ways to do this based on your data. Can you give a sample data to us, so we could easier show the possibilities for your case?

There is already quite many answers for this questions on community, so you could try to found those also.

r. Ismo

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

All Work and No Play? Not at .conf26! Unwind at These Evening Events

Between hands-on technical sessions, keynote reveals, and diving into live architectures, .conf26 is packed ...

Join the Hackathon at .conf26 and build a No-Code AI agent

Join us for the AI Agent Buildathon, an in-person, three-hour hands-on Hackathon where you’ll use Splunk Agent ...

Level Up Your Workflow: Mastering Splunk Cloud Management via Terraform

Tech Talk Recap   From Chaos to Control: Scaling Splunk Cloud with Infrastructure as Code Managing apps in ...