<?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: Time difference calculation between events grouped under transaction command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Time-difference-calculation-between-events-grouped-under/m-p/501490#M139632</link>
    <description>&lt;P&gt;Thanks for the answer. Little more trouble. What needs to be done If we want to treat the input I provided above as a result of one transaction query instead of individual logs ?&lt;/P&gt;</description>
    <pubDate>Fri, 27 Mar 2020 16:44:49 GMT</pubDate>
    <dc:creator>M46196</dc:creator>
    <dc:date>2020-03-27T16:44:49Z</dc:date>
    <item>
      <title>Time difference calculation between events grouped under transaction command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Time-difference-calculation-between-events-grouped-under/m-p/501488#M139630</link>
      <description>&lt;P&gt;I have an use case to calculate time difference between events grouped together by transaction command. Example is given below.&lt;/P&gt;

&lt;P&gt;{&lt;BR /&gt;
    "timeStamp": "Fri 2020.03.27 01:10:34:1034 AM EDT",&lt;BR /&gt;
    "step": "A"&lt;BR /&gt;
}&lt;BR /&gt;
{&lt;BR /&gt;
    "timeStamp": "Fri 2020.03.27 01:10:38:1038 AM EDT",&lt;BR /&gt;
    "step": "B",&lt;BR /&gt;
}&lt;BR /&gt;
{&lt;BR /&gt;
    "timeStamp": "Fri 2020.03.27 01:10:39:1039 AM EDT",&lt;BR /&gt;
    "step": "C"&lt;BR /&gt;
}&lt;BR /&gt;
{&lt;BR /&gt;
    "timeStamp": "Fri 2020.03.27 01:10:40:1034 AM EDT",&lt;BR /&gt;
    "step": "D"&lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;I have two requirements.&lt;/P&gt;

&lt;P&gt;Will it be possible to get time difference between consecutive steps ? &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; STEP B         4 sec
 STEP C         1 sec
 STEP D         1 sec
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If above is possible how can I get average elapsed time between two steps for all the transactions which have Step A, B, C, D ?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 06:20:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Time-difference-calculation-between-events-grouped-under/m-p/501488#M139630</guid>
      <dc:creator>M46196</dc:creator>
      <dc:date>2020-03-27T06:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference calculation between events grouped under transaction command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Time-difference-calculation-between-events-grouped-under/m-p/501489#M139631</link>
      <description>&lt;P&gt;Convert field timeStamp to epoch and use delta command to find out delta. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval timeStamp_epoch=strptime(timeStamp, "%a %Y.%m.%d %I:%M:%S:%4N %p %Z") 
| delta timeStamp_epoch p=1 AS diff 
| eval diff=round(diff, 0)." sec" 
| where isnotnull(diff) 
| table step, diff
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sample query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval data="{
\"timeStamp\": \"Fri 2020.03.27 01:10:34:1034 AM EDT\",
\"step\": \"A\"
}
{
\"timeStamp\": \"Fri 2020.03.27 01:10:38:1038 AM EDT\",
\"step\": \"B\",
}
{
\"timeStamp\": \"Fri 2020.03.27 01:10:39:1039 AM EDT\",
\"step\": \"C\"
}
{
\"timeStamp\": \"Fri 2020.03.27 01:10:40:1034 AM EDT\",
\"step\": \"D\"
}" 
| eval data=split(data, "}") 
| mvexpand data 
| rex field=data "timeStamp\":\s\"(?&amp;lt;timeStamp&amp;gt;.*)\",\s*\"step\":\s\"(?&amp;lt;step&amp;gt;\w)" 
| eval timeStamp_epoch=strptime(timeStamp, "%a %Y.%m.%d %I:%M:%S:%4N %p %Z") 
| delta timeStamp_epoch p=1 AS diff 
| eval diff=round(diff, 0)." sec" 
| where isnotnull(diff) 
| table step, diff
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Mar 2020 14:00:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Time-difference-calculation-between-events-grouped-under/m-p/501489#M139631</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2020-03-27T14:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference calculation between events grouped under transaction command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Time-difference-calculation-between-events-grouped-under/m-p/501490#M139632</link>
      <description>&lt;P&gt;Thanks for the answer. Little more trouble. What needs to be done If we want to treat the input I provided above as a result of one transaction query instead of individual logs ?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 16:44:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Time-difference-calculation-between-events-grouped-under/m-p/501490#M139632</guid>
      <dc:creator>M46196</dc:creator>
      <dc:date>2020-03-27T16:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference calculation between events grouped under transaction command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Time-difference-calculation-between-events-grouped-under/m-p/501491#M139633</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{
 \"timeStamp\": \"Fri 2020.03.27 01:10:34:1034 AM EDT\",
 \"step\": \"A\"
     }
 {
 \"timeStamp\": \"Fri 2020.03.27 01:10:38:1038 AM EDT\",
 \"step\": \"B\",
 }
 {
 \"timeStamp\": \"Fri 2020.03.27 01:10:39:1039 AM EDT\",
 \"step\": \"C\"
     }
 {
 \"timeStamp\": \"Fri 2020.03.27 01:10:40:1034 AM EDT\",
 \"step\": \"D\"
     }" 
| rex max_match=0 "\"timeStamp\":\s*\"(?&amp;lt;timeStamp&amp;gt;[^\"]+)\"" 
| rex max_match=0 "\"step\":\s*\"(?&amp;lt;step&amp;gt;[^\"]+)\"" 
| eval _counter=mvrange(0,mvcount(step)) 
| stats values(*) as * by _counter 
| foreach * 
    [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = mvindex('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' , _counter) ] 
| fields - _* 
| eval _time=strptime(timeStamp,"%a %Y.%m.%d %I:%M:%S:%4N %p %Z") 
| delta _time as diff 
| fillnull diff 
| eval session = 1 
| stats list(*) as * by session
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Mar 2020 04:31:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Time-difference-calculation-between-events-grouped-under/m-p/501491#M139633</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-28T04:31:03Z</dc:date>
    </item>
  </channel>
</rss>

