<?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 in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106837#M183280</link>
    <description>&lt;P&gt;Create a transaction and grab the length of the session from the field &lt;CODE&gt;duration&lt;/CODE&gt; that will be automatically calculated for you.&lt;/P&gt;

&lt;P&gt;If you have some unique identifier that is valid for each session you could use this to identify each session. For instance if a session can be identified by that the field &lt;CODE&gt;session_id&lt;/CODE&gt; has a unique value, do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | transaction session_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are other ways of defining how transactions should be created as well, all covered in the manual: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Nov 2011 21:50:22 GMT</pubDate>
    <dc:creator>Ayn</dc:creator>
    <dc:date>2011-11-08T21:50:22Z</dc:date>
    <item>
      <title>time difference calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106835#M183278</link>
      <description>&lt;P&gt;I have a log which says when session was created and destroyed. What search string should I use to calculate the length of session??&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2011 21:18:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106835#M183278</guid>
      <dc:creator>keshab</dc:creator>
      <dc:date>2011-11-08T21:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: time difference calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106836#M183279</link>
      <description>&lt;P&gt;Can  you post a copy of the log? that would help me craft a search for you. Assuming that the session start time and session end times are being extracted as fields already and are in every event, the following should work. Essentially, you are going to have to use the eval command. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yoursearch&amp;gt; | eval starttime=strftime(sessionstart, "%d:%H:%M:%S") | eval endtime=strftime(sessionend, "%d:%H:%M:%S") | eval session_duration=endtime-starttime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Nov 2011 21:43:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106836#M183279</guid>
      <dc:creator>RicoSuave</dc:creator>
      <dc:date>2011-11-08T21:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: time difference calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106837#M183280</link>
      <description>&lt;P&gt;Create a transaction and grab the length of the session from the field &lt;CODE&gt;duration&lt;/CODE&gt; that will be automatically calculated for you.&lt;/P&gt;

&lt;P&gt;If you have some unique identifier that is valid for each session you could use this to identify each session. For instance if a session can be identified by that the field &lt;CODE&gt;session_id&lt;/CODE&gt; has a unique value, do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | transaction session_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are other ways of defining how transactions should be created as well, all covered in the manual: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2011 21:50:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106837#M183280</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2011-11-08T21:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: time difference calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106838#M183281</link>
      <description>&lt;P&gt;2011-11-09 03:48:41,545 [INFO ] Created sessionid: 8F164BD481ADB7322448A21FEAA0178D&lt;/P&gt;

&lt;P&gt;2011-11-09 03:55:31,545 [INFO ] destroyed sessionid: 8F164BD481ADB7322448A21FEAA0178D&lt;/P&gt;

&lt;P&gt;2011-11-09 04:18:41,545 [INFO ] Created sessionid: 8F164BD481ADB7322448A21FE3434DQA&lt;/P&gt;

&lt;P&gt;2011-11-09 04:57:31,545 [INFO ] destroyed sessionid: 8F164BD481ADB7322448A21FE3434DQA&lt;/P&gt;

&lt;P&gt;What I am trying to do is calculate the session length of each session and find the average of all the session and graph the average session on the chart.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2011 15:11:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106838#M183281</guid>
      <dc:creator>keshab</dc:creator>
      <dc:date>2011-11-09T15:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: time difference calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106839#M183282</link>
      <description>&lt;P&gt;Hi there, &lt;/P&gt;

&lt;P&gt;given your logs this is accomplished by;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search giving the sample events&amp;gt; | transaction sessionid | timechart avg(duration) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Of course, you may want to change the charting options.&lt;/P&gt;

&lt;P&gt;hope this helps,&lt;/P&gt;

&lt;P&gt;Kristian&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2011 20:14:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106839#M183282</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2011-11-09T20:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: time difference calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106840#M183283</link>
      <description>&lt;P&gt;The &lt;CODE&gt;transaction&lt;/CODE&gt; command is great for this, and works well as a general solution.  However, for some purposes, you can accomplish the same thing more efficiently using &lt;CODE&gt;stats&lt;/CODE&gt;.  This may be a pretty good example of that - you're only dealing with two events.  Something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;INFO sessionid 
| rex "(Created|destroyed) sessionid: (?&amp;lt;sessionid&amp;gt;[^\s]+)" 
| stats min(_time) as begins, max(_time) as ends by sessionid
| eval duration=ends-begins
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Some assumptions here include that you don't necessarily have &lt;CODE&gt;sessionid&lt;/CODE&gt; extracted out as a field yet.  If you do, you can skip the &lt;CODE&gt;rex&lt;/CODE&gt; command.  Also, it assumes that a single &lt;CODE&gt;sessionid&lt;/CODE&gt; value is not reused within the search window and that both the beginning and ending of the session occur within the search window.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2011 13:10:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-difference-calculation/m-p/106840#M183283</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2011-11-16T13:10:46Z</dc:date>
    </item>
  </channel>
</rss>

