<?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 How to calculate length of session in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-length-of-session/m-p/103638#M183077</link>
    <description>&lt;P&gt;I have ssh events in the following log format:&lt;/P&gt;

&lt;P&gt;sshd[31922]: pam_unix(sshd:session): session closed for user root&lt;/P&gt;

&lt;P&gt;sshd[31922]: pam_unix(sshd:session): session opened for user root by (uid=0)&lt;/P&gt;

&lt;P&gt;sshd[30954]: pam_unix(sshd:session): session closed for user root&lt;/P&gt;

&lt;P&gt;sshd[30954]: pam_unix(sshd:session): session opened for user root by (uid=0)&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;How difficult would it be to generate a report each week that lists each session and its length?&lt;/P&gt;

&lt;P&gt;It seems like I need to do something similar to this thread (&lt;A href="http://splunk-base.splunk.com/answers/4886/eval-time-between-events-for-transaction-by-group"&gt;http://splunk-base.splunk.com/answers/4886/eval-time-between-events-for-transaction-by-group&lt;/A&gt;), but I'm not sure exactly how I would apply this to my situation - how do I ensure that the proper session open and close events are correlated?&lt;/P&gt;</description>
    <pubDate>Thu, 03 Nov 2011 22:00:35 GMT</pubDate>
    <dc:creator>crobicha</dc:creator>
    <dc:date>2011-11-03T22:00:35Z</dc:date>
    <item>
      <title>How to calculate length of session</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-length-of-session/m-p/103638#M183077</link>
      <description>&lt;P&gt;I have ssh events in the following log format:&lt;/P&gt;

&lt;P&gt;sshd[31922]: pam_unix(sshd:session): session closed for user root&lt;/P&gt;

&lt;P&gt;sshd[31922]: pam_unix(sshd:session): session opened for user root by (uid=0)&lt;/P&gt;

&lt;P&gt;sshd[30954]: pam_unix(sshd:session): session closed for user root&lt;/P&gt;

&lt;P&gt;sshd[30954]: pam_unix(sshd:session): session opened for user root by (uid=0)&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;How difficult would it be to generate a report each week that lists each session and its length?&lt;/P&gt;

&lt;P&gt;It seems like I need to do something similar to this thread (&lt;A href="http://splunk-base.splunk.com/answers/4886/eval-time-between-events-for-transaction-by-group"&gt;http://splunk-base.splunk.com/answers/4886/eval-time-between-events-for-transaction-by-group&lt;/A&gt;), but I'm not sure exactly how I would apply this to my situation - how do I ensure that the proper session open and close events are correlated?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2011 22:00:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-length-of-session/m-p/103638#M183077</guid>
      <dc:creator>crobicha</dc:creator>
      <dc:date>2011-11-03T22:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate length of session</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-length-of-session/m-p/103639#M183078</link>
      <description>&lt;P&gt;Looking at the question you linked to, that one covers how to calculate the time &lt;EM&gt;between&lt;/EM&gt; sessions whereas in your case you need to calculate the time &lt;EM&gt;within&lt;/EM&gt; the session. This should be pretty easy to achieve by creating a transaction based on the pid. Assuming you have the pid extracted into a field with the same name, just do&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | transaction pid startswith="session opened" endswith="session closed"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When the &lt;CODE&gt;transaction&lt;/CODE&gt; command creates transactions, it always outputs a field for each transaction called "duration", which is exactly what it sounds like - the duration of the transaction, in seconds. So to get a table of all sessions and their lengths, do something like this (assuming you have the user extracted into a field called "user"):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | transaction pid startswith="session opened" endswith="session closed" | table _time user duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Nov 2011 22:22:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-length-of-session/m-p/103639#M183078</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2011-11-03T22:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate length of session</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-length-of-session/m-p/103640#M183079</link>
      <description>&lt;P&gt;Thanks Ayn, that's exactly what I needed!&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2011 14:18:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-length-of-session/m-p/103640#M183079</guid>
      <dc:creator>crobicha</dc:creator>
      <dc:date>2011-11-04T14:18:40Z</dc:date>
    </item>
  </channel>
</rss>

