<?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 search the sum of transactions where the times do not overlap? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-sum-of-transactions-where-the-times-do-not/m-p/140443#M38812</link>
    <description>&lt;P&gt;Something as simple as  &lt;CODE&gt;...| stats sum(dur) AS time by user, machine, license&lt;/CODE&gt; won't do it, I presume?  &lt;/P&gt;

&lt;P&gt;If that works, great.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  ( &lt;CODE&gt;...| eval license_time_in_minutes=time/60&lt;/CODE&gt; could come in handy if you need it in minutes.... )&lt;/P&gt;

&lt;P&gt;If not... next reasonably easy possibility:  &lt;CODE&gt;... | streamstats sum(dur) AS time by user, machine, license&lt;/CODE&gt;?   That'll be a running sum for that, so it's not quite right, either.&lt;/P&gt;

&lt;P&gt;If I'm not quite on the right track, could you post a bit of the data you have and perhaps the output you have so far?  It might go far to helping us figure out precisely what it is still missing.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jul 2015 21:04:00 GMT</pubDate>
    <dc:creator>Richfez</dc:creator>
    <dc:date>2015-07-28T21:04:00Z</dc:date>
    <item>
      <title>How to search the sum of transactions where the times do not overlap?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-sum-of-transactions-where-the-times-do-not/m-p/140439#M38808</link>
      <description>&lt;P&gt;I want to be able to show the sum of time that users have had licenses checked out (historically). But if a user has two of the same license checked out at any given time, I only want one to be added to the tally. If the times overlap (concurrent transaction from the same user) I only want that time counted once in the sum. For example, if there are 3 transactions: one from 9:00 to 9:15, one from 9:00 to 9:30 and one from 8:30 to 10:00 I would want the sum to show as 1.5 hours.&lt;/P&gt;

&lt;P&gt;These transactions are created to be unique to 3 fields, so I would need these 3 fields to be included in the results (user, license, machine name) .&lt;/P&gt;

&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 16:57:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-sum-of-transactions-where-the-times-do-not/m-p/140439#M38808</guid>
      <dc:creator>cmamer</dc:creator>
      <dc:date>2015-07-28T16:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the sum of transactions where the times do not overlap?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-sum-of-transactions-where-the-times-do-not/m-p/140440#M38809</link>
      <description>&lt;P&gt;If I read this correctly, you want to create "transactions" out of license usage, disregarding concurrent use.  So, given the following data (with a couple extra lines added for controls):&lt;/P&gt;

&lt;P&gt;user        license machine     start               end&lt;BR /&gt;
Me      Adobe   MyMachine   7/28/2015 7:00  7/28/2015 8:10&lt;BR /&gt;
Me      Adobe   MyMachine   7/28/2015 9:00  7/28/2015 9:15&lt;BR /&gt;
Me      Adobe   MyMachine   7/28/2015 9:00  7/28/2015 9:30&lt;BR /&gt;
Me      Adobe   MyMachine   7/28/2015 8:30  7/28/2015 10:00&lt;BR /&gt;
Me      Adobe   MyMachine   7/28/2015 11:00 7/28/2015 11:04&lt;/P&gt;

&lt;P&gt;You would want one output line (duration 1:10) for the first line, ONE created out of the middle three lines (duration 1.5 hours, starting at 8:30 and ending at 10:00), then one more output line for 4 minutes from the last line?&lt;/P&gt;

&lt;P&gt;Turns out for the data as I have it above, I don't even need transaction because I discard all the lines that we don't need and each remaining event is self contained:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search that returns data like the above&amp;gt; 
| eval dur=strptime(end,"%m/%d/%Y %H:%M")-strptime(start,"%m/%d/%Y %H:%M") 
| concurrency duration=dur start=_time 
| search concurrency=1 
| table user, machine, license, start, end , dur
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Fill in your search, then each line can be added one by one to check the results.  &lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Explanation:&lt;/EM&gt;&lt;BR /&gt;
The first "eval" takes two time fields which happen to be formatted as the ones I posted above and subtracts them to get a duration called "dur" (to not conflict with the transaction's duration later).  You may already have a duration, in which case you don't need this.  Likewise, if your start and end times are epoch (e.g. integers) you can just do the math directly with them, like "eval dur=end-start"&lt;/P&gt;

&lt;P&gt;The "concurrency" then counts overlapping events.  &lt;/P&gt;

&lt;P&gt;The "search" line then only matches lines with a concurrency of 1.  In other words, only events that don't overlap with other events are included, the others are not.&lt;/P&gt;

&lt;P&gt;The "table" at the end just makes it pretty, listing the start/end time of the license usage and the duration of it in seconds.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 19:44:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-sum-of-transactions-where-the-times-do-not/m-p/140440#M38809</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2015-07-28T19:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the sum of transactions where the times do not overlap?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-sum-of-transactions-where-the-times-do-not/m-p/140441#M38810</link>
      <description>&lt;P&gt;To clarify, I also want the times of the non-concurrent transactions to be part of the sum, so in rich7177's answer below I would want the durations of the first and last lines added as well. &lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 20:17:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-sum-of-transactions-where-the-times-do-not/m-p/140441#M38810</guid>
      <dc:creator>cmamer</dc:creator>
      <dc:date>2015-07-28T20:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the sum of transactions where the times do not overlap?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-sum-of-transactions-where-the-times-do-not/m-p/140442#M38811</link>
      <description>&lt;P&gt;I already have the duration of each transaction, but I'm looking for the sum of the transaction durations without double-counting concurrent transactions, so I would want my results to look like this (using your example events):&lt;/P&gt;

&lt;P&gt;Me Adobe MyMachine 164 minutes--------&amp;gt; (70 mins + 90 mins + 4 mins )&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 20:25:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-sum-of-transactions-where-the-times-do-not/m-p/140442#M38811</guid>
      <dc:creator>cmamer</dc:creator>
      <dc:date>2015-07-28T20:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the sum of transactions where the times do not overlap?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-sum-of-transactions-where-the-times-do-not/m-p/140443#M38812</link>
      <description>&lt;P&gt;Something as simple as  &lt;CODE&gt;...| stats sum(dur) AS time by user, machine, license&lt;/CODE&gt; won't do it, I presume?  &lt;/P&gt;

&lt;P&gt;If that works, great.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  ( &lt;CODE&gt;...| eval license_time_in_minutes=time/60&lt;/CODE&gt; could come in handy if you need it in minutes.... )&lt;/P&gt;

&lt;P&gt;If not... next reasonably easy possibility:  &lt;CODE&gt;... | streamstats sum(dur) AS time by user, machine, license&lt;/CODE&gt;?   That'll be a running sum for that, so it's not quite right, either.&lt;/P&gt;

&lt;P&gt;If I'm not quite on the right track, could you post a bit of the data you have and perhaps the output you have so far?  It might go far to helping us figure out precisely what it is still missing.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 21:04:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-sum-of-transactions-where-the-times-do-not/m-p/140443#M38812</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2015-07-28T21:04:00Z</dc:date>
    </item>
  </channel>
</rss>

