Splunk Search

How to search the duration between two events in the same field?

prashanthberam
Explorer

Hi,

Hi everyone. I need to find out the duration between two events in the same field. My table is like this:

user     entry type     timestamp
raju      in            epochtime
raju      out           epochtime

help me guys ....thanks in advance

0 Karma
1 Solution

somesoni2
Revered Legend

Try like this. The chart command should create fields with same name as values in the field "entry type". The same field names will be used to calculate duration. If the values for the field "entry type" are not 'in' and 'out', you'd need to update those in line 3.

your current search giving fields user  "entry type" timestamp
| chart values(timestamp) over user by "entry type"
| eval duration=out-in
| table user in out duration

View solution in original post

0 Karma

somesoni2
Revered Legend

Try like this. The chart command should create fields with same name as values in the field "entry type". The same field names will be used to calculate duration. If the values for the field "entry type" are not 'in' and 'out', you'd need to update those in line 3.

your current search giving fields user  "entry type" timestamp
| chart values(timestamp) over user by "entry type"
| eval duration=out-in
| table user in out duration
0 Karma

gokadroid
Motivator

Can you check if either of these works:

If every userName data exists only once for in and out events so that we can use username to group all the activities from "in" to "out" as transaction events user did, then use:

index=yourIndexyour sourcetype=yourSourceType "entry type"="in" OR "entry type"="out"
| transaction user
| table user, duration

Above also assumes the timestamp are of same format.

If username data exists for more than one in and out events where user might have come in and gone out more than once they try this:

 index=yourIndexyour sourcetype=yourSourceType "entry type"="in" OR "entry type"="out"
|  sort user, timestamp
| autoregress user as newUserName p=1
| autoregress timestamp as newTimeStamp p=1
| eval durationTime=(timestamp-newTimeStamp)
| eval userDuration=if( user=newUserName AND 'entry type'="out"), durationTime, 0)
| table user, userDuration | where userDuration > 0

Based on the userDuration values you can accordingly divide by 60, 3600 etc. to get the userDuration in the format you like.

0 Karma

gokadroid
Motivator

Can you check if your user, event type and timestamp fields are called "user", "event type" and "timestamp"?

The only reason all values will come in one column is if transaction command is being done on a field which has the same value for all the events in your data, say something like "userType=visitor" where all users are visitors and we did |transaction userType

0 Karma

prashanthberam
Explorer

am getting the whole users results in a single column.but i want individual person duration

i need like this
user duration
raju 10 sec
rani 11 sec

like this ...........
thanks

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 ...