<?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 the difference between two timestamps from the same event? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171410#M49096</link>
    <description>&lt;P&gt;Thanks a lot! It worked.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Oct 2014 22:25:07 GMT</pubDate>
    <dc:creator>chandravadanj</dc:creator>
    <dc:date>2014-10-22T22:25:07Z</dc:date>
    <item>
      <title>How to calculate the difference between two timestamps from the same event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171404#M49090</link>
      <description>&lt;P&gt;I need suggestion to write a search query to calculate a difference between the timestamps for the same event. Following is the sample of the event from the file. Each event can have multiple lines, those are not fixed.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;A = First I want to get the value "2014-10-18T04:10:06.303Z" from the line which contains "GET /search".&lt;/LI&gt;
&lt;LI&gt;B = Then I want to read the value "2014-10-18T04:10:06.189Z" from the line which contains "OPTIONS /search"&lt;/LI&gt;
&lt;LI&gt;Then Result = A - B. which is in this case will be 114 millisecond.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;{"name":"Test API","hostname":"ip-XXX-XX-XX-XX","pid":8453,"level":30,"msg":"Server started running on 9080","time":"2014-10-18T04:07:46.991Z","v":0} &lt;BR /&gt;
{"name":"Periscope API","hostname":"ip-XXX-XX-XX-XX","pid":8464,"level":30,"msg":"Server started running on 9080","time":"2014-10-18T04:08:50.242Z","v":0} &lt;BR /&gt;
{"name":"Test API","hostname":"ip-XXX-XX-XX-XX","pid":8469,"level":30,"msg":"Server started running on 8080","time":"2014-10-18T04:09:57.734Z","v":0} &lt;BR /&gt;
{"name":"Periscope API","hostname":"ip-XXX-XX-XX-XX","pid":8469,"level":30,"msg":&lt;STRONG&gt;"OPTIONS /search&lt;/STRONG&gt;/test/cursor/initial/size/1000","time":"&lt;STRONG&gt;2014-10-18T04:10:06.189Z&lt;/STRONG&gt;","v":0}&lt;BR /&gt;
 {"name":"Periscope API","hostname":"ip-XXX-XX-XX-XX","pid":8469,"level":30,"msg":&lt;STRONG&gt;"GET /search&lt;/STRONG&gt;/test/cursor/initial/size/1000","time":"&lt;STRONG&gt;2014-10-18T04:10:06.303Z&lt;/STRONG&gt;","v":0}&lt;BR /&gt;
 {"name":"Periscope API","hostname":"ip-XXX-XX-XX-XX","pid":8469,"level":30,"query":"test","cursor":"initial","return":"_all_fields","queryParser":"simple","size":"1000","msg":"","time":"2014-10-18T04:10:06.309Z","v":0}&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:56:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171404#M49090</guid>
      <dc:creator>chandravadanj</dc:creator>
      <dc:date>2020-09-28T17:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two timestamps from the same event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171405#M49091</link>
      <description>&lt;P&gt;How can those two events be correlated? Start as a human rather than trying to write a search straight away.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Oct 2014 20:25:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171405#M49091</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-10-22T20:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two timestamps from the same event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171406#M49092</link>
      <description>&lt;P&gt;Thanks for the replay.&lt;/P&gt;

&lt;P&gt;I am not sure how can we correlate them. Is it possible to read the 2 timestamp values for the single log event and get the difference between those to into a variable. We have this log when the process starts and ends. OPTIONS is start time and GET is end time. We need to find out the difference to know the time taken by these step.&lt;/P&gt;

&lt;P&gt;LINE 1 in the Event : {"name":"Periscope API","hostname":"ip-XXX-XX-XX-XX","pid":8469,"level":30,"msg":"OPTIONS /search/test/cursor/initial/size/1000","time":"2014-10-18T04:10:06.189Z","v":0}&lt;/P&gt;

&lt;P&gt;LINE 2 in the Event : {"name":"Periscope API","hostname":"ip-XXX-XX-XX-XX","pid":8469,"level":30,"msg":"GET /search/test/cursor/initial/size/1000","time":"2014-10-18T04:10:06.303Z","v":0}&lt;/P&gt;</description>
      <pubDate>Wed, 22 Oct 2014 21:47:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171406#M49092</guid>
      <dc:creator>chandravadanj</dc:creator>
      <dc:date>2014-10-22T21:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two timestamps from the same event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171407#M49093</link>
      <description>&lt;P&gt;Is that entire block of text one Splunk event?&lt;/P&gt;

&lt;P&gt;If so, extract both timestamps into two fields, use &lt;CODE&gt;strptime()&lt;/CODE&gt; to get the epoch timestamp and subtract one from the other.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Oct 2014 21:54:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171407#M49093</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-10-22T21:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two timestamps from the same event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171408#M49094</link>
      <description>&lt;P&gt;Yes, the entire block of text is one splunk event.&lt;/P&gt;

&lt;P&gt;I need to help on the syntax how to extract those both the timestamps into the two fields. Could you please help me with a sample.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Oct 2014 21:58:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171408#M49094</guid>
      <dc:creator>chandravadanj</dc:creator>
      <dc:date>2014-10-22T21:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two timestamps from the same event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171409#M49095</link>
      <description>&lt;P&gt;If that's all one big event then there's no need to correlate anything.&lt;/P&gt;

&lt;P&gt;Untested, but this should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "OPTIONS /search.*?\"time\"\D+(?&amp;lt;optionsTime&amp;gt;[^\"]+)"
    | rex "GET /search.*?\"time\"\D+(?&amp;lt;getTime&amp;gt;[^\"]+)" 
    | eval diff = strptime(getTime, "%Y-%m-%dT%H:%M:%S.%3N%Z") - strptime(optionsTime, "%Y-%m-%dT%H:%M:%S.%3N%Z")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Oct 2014 22:08:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171409#M49095</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-10-22T22:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two timestamps from the same event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171410#M49096</link>
      <description>&lt;P&gt;Thanks a lot! It worked.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Oct 2014 22:25:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-timestamps-from-the/m-p/171410#M49096</guid>
      <dc:creator>chandravadanj</dc:creator>
      <dc:date>2014-10-22T22:25:07Z</dc:date>
    </item>
  </channel>
</rss>

