<?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: Get the time difference between 2 different events based on common fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404500#M116996</link>
    <description>&lt;P&gt;Could you tell more about these events, like, will there be multiple such pair for a specific actionId and poolId, what you want to do if your selected time range includes partial events (e.g. only includes DataLoadingStartedEvent OR DataLoadingCompletedEvent )? &lt;/P&gt;

&lt;P&gt;Generally, you'd do something like this (assuming you've setup a field extraction for extraction e.g. eventType=DataLoadingStartedEvent OR DataLoadingCompletedEvent)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo sourcetype=bar eventType=DataLoadingStartedEvent OR eventType=DataLoadingCompletedEvent
| eval startTime=if(eventType=DataLoadingStartedEvent,_time,null())
| eval endTime=if(eventType=DataLoadingCompletedEvent,_time,null())
| stats min(startTime) as startTime max(endTime) as endTime by  actionId poolId  
| eval duration=endTime-startTime 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 14 Jan 2019 21:03:40 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2019-01-14T21:03:40Z</dc:date>
    <item>
      <title>Get the time difference between 2 different events based on common fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404499#M116995</link>
      <description>&lt;P&gt;I have a log  that shows when the particular event was fired &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;2019-01-14 19:20:21,849 [DEBUG] [c.h.d.s.i.AsynchronousEventPublicationService] Firing data hub event : DataLoadingStartedEvent{actionId=553, feedId=37, poolId=37}&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;And another log that shows when the event fired event has completed &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;2019-01-14 19:20:22,029 [DEBUG] [c.h.d.s.i.AsynchronousEventPublicationService] Firing data hub event : DataLoadingCompletedEvent{actionId=553, feedId=37, poolId=37}&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;There are many similar such events. I need to calculate the time it took to finish based on the actionId and poolId.&lt;BR /&gt;
Both the start and finish event needs to have the same actionId and poolId.To calculate the finish time we need to find the difference between DataLoadingStartedEvent and DataLoadingCompletedEvent . How can I achieve this?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jan 2019 19:31:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404499#M116995</guid>
      <dc:creator>mrafiq17</dc:creator>
      <dc:date>2019-01-14T19:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Get the time difference between 2 different events based on common fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404500#M116996</link>
      <description>&lt;P&gt;Could you tell more about these events, like, will there be multiple such pair for a specific actionId and poolId, what you want to do if your selected time range includes partial events (e.g. only includes DataLoadingStartedEvent OR DataLoadingCompletedEvent )? &lt;/P&gt;

&lt;P&gt;Generally, you'd do something like this (assuming you've setup a field extraction for extraction e.g. eventType=DataLoadingStartedEvent OR DataLoadingCompletedEvent)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo sourcetype=bar eventType=DataLoadingStartedEvent OR eventType=DataLoadingCompletedEvent
| eval startTime=if(eventType=DataLoadingStartedEvent,_time,null())
| eval endTime=if(eventType=DataLoadingCompletedEvent,_time,null())
| stats min(startTime) as startTime max(endTime) as endTime by  actionId poolId  
| eval duration=endTime-startTime 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Jan 2019 21:03:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404500#M116996</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-01-14T21:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get the time difference between 2 different events based on common fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404501#M116997</link>
      <description>&lt;P&gt;Hi somesoni2,&lt;BR /&gt;
Thank you for the answer. &lt;/P&gt;

&lt;P&gt;I have seen multiple pairs. I am getting the duration wrong as there are multiple pairs as I didn't inform earlier. I used the transaction command and I am getting the correct duration.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;DataLoading*Event |transaction actionId poolId startswith="DataLoadingStartedEvent" endswith="DataLoadingCompletedEvent"|eval time=(duration/60)|table actionId poolId time&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Regarding the partial events, I have noticed that the startedevent has fired while the completedevent is not present. In such cases, I would we need to go an hour earlier and look for the action id along with the poolid for the startedevent and then get the time from completedevent to calculate the duration. I tried subsearch, but I am not able to form a query.&lt;/P&gt;

&lt;P&gt;Could you please help?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jan 2019 21:33:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404501#M116997</guid>
      <dc:creator>mrafiq17</dc:creator>
      <dc:date>2019-01-14T21:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Get the time difference between 2 different events based on common fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404502#M116998</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
You could use the  &lt;CODE&gt;transaction&lt;/CODE&gt; command with the &lt;CODE&gt;endswith&lt;/CODE&gt; and &lt;CODE&gt;startwisth&lt;/CODE&gt; options&lt;/P&gt;

&lt;P&gt;here's the documentation on transaction with other options you could use to optimize your search&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.0/SearchReference/Transaction"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.0/SearchReference/Transaction&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 08:15:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404502#M116998</guid>
      <dc:creator>bangalorep</dc:creator>
      <dc:date>2019-01-15T08:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Get the time difference between 2 different events based on common fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404503#M116999</link>
      <description>&lt;P&gt;Hi bangalorep,&lt;/P&gt;

&lt;P&gt;I have tried the transaction command, it's not accurate. I have found that around 60% was correct while other events did have a closing event but still came as events where no closing events existed. Below is the query&lt;/P&gt;

&lt;P&gt;** DataLoading*Event | transaction actionId poolId  startswith="DataLoadingStartedEvent" endswith="DataLoadingCompletedEvent" keepevicted=true|search closed_txn=0 AND evicted&amp;gt;=0|eval diff=tostring(now()-_time,"duration") | table diff&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:46:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404503#M116999</guid>
      <dc:creator>mrafiq17</dc:creator>
      <dc:date>2020-09-29T22:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Get the time difference between 2 different events based on common fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404504#M117000</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
If you use the  &lt;CODE&gt;transaction&lt;/CODE&gt; command the duration is automatically calculated.  You could search for duration and add it as an interesting field on the list of fields to the left side&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 12:17:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404504#M117000</guid>
      <dc:creator>bangalorep</dc:creator>
      <dc:date>2019-01-15T12:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Get the time difference between 2 different events based on common fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404505#M117001</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;The duration would not be calculated as the transaction is not complete. Hence I had to find the time difference by deducting current time from the event time.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 12:54:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404505#M117001</guid>
      <dc:creator>mrafiq17</dc:creator>
      <dc:date>2019-01-15T12:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Get the time difference between 2 different events based on common fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404506#M117002</link>
      <description>&lt;P&gt;In your search what is this part for?  &lt;CODE&gt;|search closed_txn=0 AND evicted&amp;gt;=0&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;You could instead run a search like  &lt;CODE&gt;NOT duration = *&lt;/CODE&gt; and the calculate the duration of the remaining events.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 07:36:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404506#M117002</guid>
      <dc:creator>bangalorep</dc:creator>
      <dc:date>2019-01-16T07:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get the time difference between 2 different events based on common fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404507#M117003</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
You can also achieve this by converting your starttime and endtime into epoch and then you can do the subtraction between them and then you can again convert time to strp format &lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 11:17:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-time-difference-between-2-different-events-based-on/m-p/404507#M117003</guid>
      <dc:creator>nikita_p</dc:creator>
      <dc:date>2019-01-16T11:17:30Z</dc:date>
    </item>
  </channel>
</rss>

