Splunk Search

How to calculate the duration between the last 2 events in a transaction?

sc0tt
Builder

I would like to calculate the duration between the last two events in a transaction. An example transaction looks something like:

2015-12-31 13:03:03,695  Outgoing  UserId="99999999999" MsgType="Menu" Internal="START" 
2015-12-31 13:03:15,437  Incoming  UserId="99999999999" MsgType="Refresh"
2015-12-31 13:03:19,847  Incoming  UserId="99999999999" MsgType="Key" Key="1" 
2015-12-31 13:03:20,238  Outgoing  UserId="99999999999" MsgType="Menu" 

How can I calculate the duration between last Incoming and last Outgoing events?

0 Karma
1 Solution

sundareshr
Legend

Try something like this... This is untested, so you will have to tweak to your data

First extract Incoming and Outgoing into a field, say dir

.... | rex "\b(?<dir>[Outgoing|Incoming]+)\b"

Then add a serial number to both directions.. like this

| streamstats count by dir

Then sort by dir to group Incoming with Outgoing

| sort dir

Finally use the range command to get the time difference

| streamstats range(_time) as diff by dir

This should give you some idea as to get what you need

View solution in original post

0 Karma

sundareshr
Legend

Try something like this... This is untested, so you will have to tweak to your data

First extract Incoming and Outgoing into a field, say dir

.... | rex "\b(?<dir>[Outgoing|Incoming]+)\b"

Then add a serial number to both directions.. like this

| streamstats count by dir

Then sort by dir to group Incoming with Outgoing

| sort dir

Finally use the range command to get the time difference

| streamstats range(_time) as diff by dir

This should give you some idea as to get what you need

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...