<?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: Transaction and Duration in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Transaction-and-Duration/m-p/158290#M44599</link>
    <description>&lt;P&gt;If a transaction represents a "session", then the following will give you the average across all sessions. Each session has its own duration, as you described it above. The average function will do what you want,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=app 
| transaction username startswith=eval(active) endswith=eval(inactive) 
| stats avg(duration) as avgDuration
| eval avgDuration = tostring(avgDuration,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;avgDuration&lt;/CODE&gt; is expressed in seconds. If you don't want the hours and seconds, you could do this to get only the minutes:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval avgDuration = round(avgDuration/60,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;One way to verify this for yourself is to look at the intermediate results. For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=app 
| transaction username startswith=eval(active) endswith=eval(inactive) 
| table username duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will show you the intermediate data that is passed to the &lt;CODE&gt;stats&lt;/CODE&gt; command.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Nov 2013 19:28:42 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2013-11-27T19:28:42Z</dc:date>
    <item>
      <title>Transaction and Duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-and-Duration/m-p/158289#M44598</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;

&lt;P&gt;Does transaction calculate duration per "transaction" or from the first event in the transaction to the last event in the last transaction (active - #1 to Inactive - #2)?  I need to average the sum of all durations of EACH transaction.&lt;/P&gt;

&lt;P&gt;sourcetype=app | transaction userA startswith=eval(active) endswith=(inactive) | stats avg(duration) | eval duration = tostring(duration,"duration")&lt;/P&gt;

&lt;P&gt;userA&lt;BR /&gt;
active - #1&lt;BR /&gt;
inactive - #1&lt;BR /&gt;
(duration #1)&lt;/P&gt;

&lt;P&gt;(Time of Inactivity is disregarded)&lt;/P&gt;

&lt;P&gt;userA&lt;BR /&gt;
active - #2&lt;BR /&gt;
Inactive - #2&lt;BR /&gt;
(duration #2)&lt;/P&gt;

&lt;P&gt;Sum = Duration #1 + Duration #2 = what I need&lt;/P&gt;

&lt;P&gt;I couldn't find this in the docs.  As a sub question how can I remove HH and SSS from the "tostring(duration, "duration") output?  I don't need either field.  Thanks everyone!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2013 16:21:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-and-Duration/m-p/158289#M44598</guid>
      <dc:creator>ctripod</dc:creator>
      <dc:date>2013-11-27T16:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction and Duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-and-Duration/m-p/158290#M44599</link>
      <description>&lt;P&gt;If a transaction represents a "session", then the following will give you the average across all sessions. Each session has its own duration, as you described it above. The average function will do what you want,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=app 
| transaction username startswith=eval(active) endswith=eval(inactive) 
| stats avg(duration) as avgDuration
| eval avgDuration = tostring(avgDuration,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;avgDuration&lt;/CODE&gt; is expressed in seconds. If you don't want the hours and seconds, you could do this to get only the minutes:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval avgDuration = round(avgDuration/60,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;One way to verify this for yourself is to look at the intermediate results. For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=app 
| transaction username startswith=eval(active) endswith=eval(inactive) 
| table username duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will show you the intermediate data that is passed to the &lt;CODE&gt;stats&lt;/CODE&gt; command.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2013 19:28:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-and-Duration/m-p/158290#M44599</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-11-27T19:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction and Duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-and-Duration/m-p/158291#M44600</link>
      <description>&lt;P&gt;Thank you!  This was very helpful.  I confirmed that the duration is for each transaction within the given time period by tabling the duration of my query, then doing the avg(duration) after confirming the question I had.  Here is the query I came up with which has a very nice format for simple human consumption.&lt;/P&gt;

&lt;P&gt;eventtype=mobile action="App_Active" OR action="App_Inactive" | transaction user_email startswith=eval(action="App_Active") endswith=eval(action="App_Inactive") | stats avg(duration) as seconds | &lt;CODE&gt;sec2time(seconds,time_spent)&lt;/CODE&gt; | fields time_spent | eval shortened = substr(time_spent,10,16) | table shortened&lt;/P&gt;

&lt;P&gt;I used a cool macro that someone out there created called "sec2time" then used substring to remove day and hour (since duration will always be at the most in minutes)&lt;/P&gt;

&lt;P&gt;Result in panel: 4m 13s&lt;/P&gt;

&lt;P&gt;Thank you again for the help!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:13:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-and-Duration/m-p/158291#M44600</guid>
      <dc:creator>ctripod</dc:creator>
      <dc:date>2020-09-29T15:13:24Z</dc:date>
    </item>
  </channel>
</rss>

