<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to calculate respose time between two events in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-respose-time-between-two-events/m-p/233693#M69431</link>
    <description>&lt;P&gt;&lt;STRONG&gt;OPTION 1 : Using stats command&lt;/STRONG&gt;&lt;BR /&gt;
Best way to do is by Stats as it will run faster and give you control over inputs/outputs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Your base Search  request_type="LeaveBidsRequest" | stats count(request_pid) as eventcount min(_time) as MinTime max(_time) as  MaxTime by request_pid | search eventcount&amp;gt;1 | eval Response_Time=(MaxTime-MinTime) | table request_pid Response_Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;OPTION 2 : Using transaction command&lt;/STRONG&gt;&lt;BR /&gt;
You can also try transaction which is easier to write but should not be executed for longer duration resulting in several thousand event matches (which might result in slowness and orphaned records).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Your base Search  request_type="LeaveBidsRequest" | transaction request_pid | search eventcount&amp;gt;1 | rename duration as  Response_Time | table request_pid Response_Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: &lt;BR /&gt;
1) Response_Time is in seconds for both examples.&lt;BR /&gt;
2) Transaction Command computes eventcount and duration automatically (based on first and last events matched).&lt;BR /&gt;
3) Use of maxpause, maxspan, keeporphaned, keepevicted, startswith and endswith should be considered for transaction to run faster. Nevertheless Transaction is only suitable if you provide Key field in your search like reques_pid in your Use case. Otherwise stats should be used for scenarios like this.&lt;BR /&gt;
4) Another scenario in all Use Case would be to find orphaned records or eventcount=1, where no match for LeaveBidsRequest is found for duration&amp;gt; defined SLA.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 11:53:51 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2020-09-29T11:53:51Z</dc:date>
    <item>
      <title>How to calculate respose time between two events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-respose-time-between-two-events/m-p/233692#M69430</link>
      <description>&lt;P&gt;I have a table as below. I need to calculate the time difference between the below two events.&lt;/P&gt;

&lt;P&gt;request_pid     _time                           Milli_Sec   request_type&lt;BR /&gt;
11600          2016-11-19 17:20:50  17.262275   LeaveBidsRequest&lt;BR /&gt;
11600          2016-11-19 17:20:51  17.803375   LeaveBidsRequest&lt;BR /&gt;
19243          2016-11-19 17:36:51  77.376436   LeaveBidsRequest&lt;BR /&gt;
19243          2016-11-19 17:36:53  78.502509   LeaveBidsRequest&lt;BR /&gt;
21012          2016-11-19 17:38:38  67.263722   LeaveBidsRequest&lt;BR /&gt;
21012          2016-11-19 17:38:38  67.678533   LeaveBidsRequest &lt;/P&gt;

&lt;P&gt;Sample output like&lt;BR /&gt;
request_pid    Response_Time&lt;BR /&gt;
11600              1.5411.&lt;/P&gt;

&lt;P&gt;Can someone help me?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:50:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-respose-time-between-two-events/m-p/233692#M69430</guid>
      <dc:creator>premselvans</dc:creator>
      <dc:date>2020-09-29T11:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate respose time between two events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-respose-time-between-two-events/m-p/233693#M69431</link>
      <description>&lt;P&gt;&lt;STRONG&gt;OPTION 1 : Using stats command&lt;/STRONG&gt;&lt;BR /&gt;
Best way to do is by Stats as it will run faster and give you control over inputs/outputs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Your base Search  request_type="LeaveBidsRequest" | stats count(request_pid) as eventcount min(_time) as MinTime max(_time) as  MaxTime by request_pid | search eventcount&amp;gt;1 | eval Response_Time=(MaxTime-MinTime) | table request_pid Response_Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;OPTION 2 : Using transaction command&lt;/STRONG&gt;&lt;BR /&gt;
You can also try transaction which is easier to write but should not be executed for longer duration resulting in several thousand event matches (which might result in slowness and orphaned records).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Your base Search  request_type="LeaveBidsRequest" | transaction request_pid | search eventcount&amp;gt;1 | rename duration as  Response_Time | table request_pid Response_Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: &lt;BR /&gt;
1) Response_Time is in seconds for both examples.&lt;BR /&gt;
2) Transaction Command computes eventcount and duration automatically (based on first and last events matched).&lt;BR /&gt;
3) Use of maxpause, maxspan, keeporphaned, keepevicted, startswith and endswith should be considered for transaction to run faster. Nevertheless Transaction is only suitable if you provide Key field in your search like reques_pid in your Use case. Otherwise stats should be used for scenarios like this.&lt;BR /&gt;
4) Another scenario in all Use Case would be to find orphaned records or eventcount=1, where no match for LeaveBidsRequest is found for duration&amp;gt; defined SLA.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:53:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-respose-time-between-two-events/m-p/233693#M69431</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T11:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate respose time between two events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-respose-time-between-two-events/m-p/233694#M69432</link>
      <description>&lt;P&gt;Hello niketnilay,&lt;/P&gt;

&lt;P&gt;Hope you are doing well.&lt;/P&gt;

&lt;P&gt;Thanks for the answer.  I've tried transaction already. But it gives difference in seconds. &lt;/P&gt;

&lt;P&gt;I would like to subtract the time as below&lt;/P&gt;

&lt;P&gt;11600 &lt;STRONG&gt;2016-11-19 17:20:50 17.262275&lt;/STRONG&gt; LeaveBidsRequest&lt;BR /&gt;
11600 &lt;STRONG&gt;2016-11-19 17:20:51 17.803375&lt;/STRONG&gt; LeaveBidsRequest&lt;/P&gt;

&lt;P&gt;Response_Time=(2016-11-19 17:20:51 17.803375) - (2016-11-19 17:20:50 17.262275)&lt;/P&gt;

&lt;P&gt;Milli_Sec is stored as a separate field. &lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 07:47:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-respose-time-between-two-events/m-p/233694#M69432</guid>
      <dc:creator>premselvans</dc:creator>
      <dc:date>2016-11-20T07:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate respose time between two events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-respose-time-between-two-events/m-p/233695#M69433</link>
      <description>&lt;P&gt;I agree with @nikenilay that stats is the best way to go. But I think there is a much easier stats command to do what you want&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Your base Search  request_type="LeaveBidsRequest" 
| stats range(_time) as Response_Time  earliest(Milli_Sec) as ems latest(Milli_Sec) as lms by request_pid
| eval Response_Time = Response_Time + lms - ems | fields - lms ems
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 07:50:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-respose-time-between-two-events/m-p/233695#M69433</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2016-11-20T07:50:41Z</dc:date>
    </item>
  </channel>
</rss>

