<?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 edit my search to calculate total duration for periods with actual events (User activity time)? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-total-duration-for-periods/m-p/229663#M68029</link>
    <description>&lt;P&gt;How frequently are the events logged and do is active vs inactive determined? Assuming the events logged are only when the user is active, you can try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats earliest(_time) as start latest(_time) as end by USER_ID | eval duration=tostring(round(end-start, 0), "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If events are logged for active as well as inactive state, try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... state="active" | stats earliest(_time) as start latest(_time) as end by USER_ID | eval duration=tostring(round(end-start, 0), "duration")**
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 16 Aug 2016 08:13:21 GMT</pubDate>
    <dc:creator>sundareshr</dc:creator>
    <dc:date>2016-08-16T08:13:21Z</dc:date>
    <item>
      <title>How to edit my search to calculate total duration for periods with actual events (User activity time)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-total-duration-for-periods/m-p/229662#M68028</link>
      <description>&lt;P&gt;Looking for help coming up with search to calculate the total duration there were events in a given time period - essentially a reflection (for the given use case) for how much time the user was actively doing something. &lt;/P&gt;

&lt;P&gt;So if user A logged in at 11 am, did 5 things between 11 and 11:01, nothing between 11:01 and 11:03 and then again between 11:03 and 11:04 did 10 things, 11:04 to 11:05 did 3 things, then in total the user was active for 3 out of the 5 mins. Only care about 1 minute granularity.&lt;/P&gt;

&lt;P&gt;I'm using transaction with maxpause of 60s to represent "inactivity" for a certain time period and then aggregate "duration" to get active_time &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| transaction USER_ID maxpause=65s | stats sum(duration) as dur | eval active_time = dur/60
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Looking for other ideas and techniques to approach this.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 04:22:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-total-duration-for-periods/m-p/229662#M68028</guid>
      <dc:creator>aladda_splunk</dc:creator>
      <dc:date>2016-08-16T04:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate total duration for periods with actual events (User activity time)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-total-duration-for-periods/m-p/229663#M68029</link>
      <description>&lt;P&gt;How frequently are the events logged and do is active vs inactive determined? Assuming the events logged are only when the user is active, you can try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats earliest(_time) as start latest(_time) as end by USER_ID | eval duration=tostring(round(end-start, 0), "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If events are logged for active as well as inactive state, try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... state="active" | stats earliest(_time) as start latest(_time) as end by USER_ID | eval duration=tostring(round(end-start, 0), "duration")**
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Aug 2016 08:13:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-total-duration-for-periods/m-p/229663#M68029</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-08-16T08:13:21Z</dc:date>
    </item>
  </channel>
</rss>

