<?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 do I calculate the Average time usage per day when using Transaction and Bin? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309582#M92862</link>
    <description>&lt;P&gt;Hello @somesoni2&lt;/P&gt;

&lt;P&gt;I am able to get the result very quickly with these Queries, Thanks.&lt;BR /&gt;
I would like to understand how the duration is calculated here.&lt;BR /&gt;
When I used Transaction, I was able to get the duration by it's total running time (calculated between 2 events).&lt;BR /&gt;
There are 2 fields RobotStart and RobotEnd in these events, if we use that, it would be perfect I suppose. They have time values that looks like "01/17/2018 16:42:07". Can we use these to get the exact results?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jan 2018 16:44:38 GMT</pubDate>
    <dc:creator>maria2691</dc:creator>
    <dc:date>2018-01-17T16:44:38Z</dc:date>
    <item>
      <title>How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309578#M92858</link>
      <description>&lt;P&gt;Hello Everyone&lt;/P&gt;

&lt;P&gt;I have 2 source types ProcessStart and ProcessEnd.&lt;BR /&gt;
The common field with which I need to find out the duration of runtime is RunID.&lt;BR /&gt;
My requirement is to find out the total time the processes are running in a particular host and show their average usage time per day.&lt;BR /&gt;
Below is my Query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype=ProcessStart OR sourcetype=ProcessEnd 
 | transaction RunID 
 | bin _time span=1d 
 | stats sum(duration) AS Duration by _time host 
 | stats avg(Duration) as "Average Usage" by host 
 | eval "Average Usage"=round(('Average Usage'/3600),2) 
 | rename host as "Virtual Machine" 
 | sort- "Average Usage"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have used Transaction on RunID and used bin command to segregate them day wise. I am able to get the final result by not by day wise. For eg: It should be below 24 hours even if I am checking the events for 100 days since the output is required to showing the total day wise average.&lt;/P&gt;

&lt;P&gt;How do I make the final Average usage by host field to calculate the whole duration and divide them by number of days?&lt;/P&gt;

&lt;P&gt;I used days=round(now()-_time) and tried to divide Average Usage/days and it doesn't work.&lt;/P&gt;

&lt;P&gt;Also I have a performance issue when running this Query, it is very slow. What would be the reason and how can I rectify it?&lt;/P&gt;

&lt;P&gt;Thanks &amp;amp; Regards&lt;BR /&gt;
Maria Arokiaraj&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 15:36:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309578#M92858</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2018-01-17T15:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309579#M92859</link>
      <description>&lt;P&gt;Do all those runID run everyday??&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 16:08:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309579#M92859</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-01-17T16:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309580#M92860</link>
      <description>&lt;P&gt;Hello @somesoni2&lt;/P&gt;

&lt;P&gt;RunIDs are created every time there is a new task on the host. The ones which already exist, does not get updated.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 16:19:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309580#M92860</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2018-01-17T16:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309581#M92861</link>
      <description>&lt;P&gt;I believe you should be using stats command instead of transaction command (very expensive command) to mitigate your performance issue.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=ProcessStart OR sourcetype=ProcessEnd 
  | eval start=if(sourcetype="ProcessStart",_time,null())
  | eval end=if(sourcetype="ProcessEnd",_time,null())
  | stats values(start) as _time values(end) as end by host RunID
  | eval duration=end-_time | bucket span=1d _time
  | stats avg(duration) AS Duration by _time host 
  | stats avg(Duration) as "Average Usage" by host 
  | eval "Average Usage"=round(('Average Usage'/3600),2) 
  | rename host as "Virtual Machine" 
  | sort- "Average Usage"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=ProcessStart OR sourcetype=ProcessEnd 
  | eval start=if(sourcetype="ProcessStart",_time,null())
  | eval end=if(sourcetype="ProcessEnd",_time,null())
  | stats values(start) as _time values(end) as end by host RunID
  | eval duration=end-_time | bucket span=1d _time
  | stats sum(duration) AS Duration by _time host 
  | stats sum(Duration) as "Average Usage" dc(_time) as days by host 
  | eval "Average Usage"=round(('Average Usage'/days/3600),2) 
  | rename host as "Virtual Machine" 
  | sort- "Average Usage"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jan 2018 16:27:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309581#M92861</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-01-17T16:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309582#M92862</link>
      <description>&lt;P&gt;Hello @somesoni2&lt;/P&gt;

&lt;P&gt;I am able to get the result very quickly with these Queries, Thanks.&lt;BR /&gt;
I would like to understand how the duration is calculated here.&lt;BR /&gt;
When I used Transaction, I was able to get the duration by it's total running time (calculated between 2 events).&lt;BR /&gt;
There are 2 fields RobotStart and RobotEnd in these events, if we use that, it would be perfect I suppose. They have time values that looks like "01/17/2018 16:42:07". Can we use these to get the exact results?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 16:44:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309582#M92862</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2018-01-17T16:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309583#M92863</link>
      <description>&lt;P&gt;With above queries, I'm using _time field of the events from sourcetype=ProcessStart and sourcetype=ProcessEnd to calculate the difference (The stats on line 4 gets both epoch timestamp values for each RunID and line 5 calculates it). If you want to use timestamp values other that _time, then you need to update line 2 and 3 to use those fields instead of _time. E.g. (only showing line 2 and 3)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval start=if(sourcetype="ProcessStart",strptime(RobotStart,"%m/%d/%Y %H:%M:%S"),null())
   | eval end=if(sourcetype="ProcessEnd",strptime(RobotEnd,"%m/%d/%Y %H:%M:%S"),null())
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jan 2018 16:59:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309583#M92863</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-01-17T16:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309584#M92864</link>
      <description>&lt;P&gt;Thanks a lot @somesoni2... It works with both the ones.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 17:38:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309584#M92864</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2018-01-17T17:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309585#M92865</link>
      <description>&lt;P&gt;Hello @somesoni2&lt;/P&gt;

&lt;P&gt;I have a problem with days calculation in the above solution shared by you.&lt;BR /&gt;
The number of days return for some hosts so dramatically high. When I am checking the events for last 1 year, the max number of days should be 365 since we are calculating the dc(_time), however the results are like 18000 for some. How would it be possible, I am trying in different ways to correct it without any success. Can you help?&lt;/P&gt;

&lt;P&gt;Thanks&lt;BR /&gt;
Maria Arokiaraj&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 16:10:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309585#M92865</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2018-02-06T16:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309586#M92866</link>
      <description>&lt;P&gt;In above query, there will be a row for each runId with different start time. What's the query you're trying?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 16:28:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309586#M92866</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-06T16:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309587#M92867</link>
      <description>&lt;P&gt;I am trying with the same query, however the issue persists &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/15147"&gt;@somesoni2&lt;/a&gt; &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;
    sourcetype=ProcessStart OR sourcetype=ProcessEnd &lt;BR /&gt;
       | eval start=if(sourcetype="ProcessStart",_time,null())&lt;BR /&gt;
       | eval end=if(sourcetype="ProcessEnd",_time,null())&lt;BR /&gt;
       | stats values(start) as _time values(end) as end by host RunID&lt;BR /&gt;
       | eval duration=end-_time | bucket span=1d _time&lt;BR /&gt;
       | stats sum(duration) AS Duration by _time host &lt;BR /&gt;
       | stats sum(Duration) as "Average Usage" dc(_time) as days by host &lt;BR /&gt;
       | eval "Average Usage"=round(('Average Usage'/days/3600),2) &lt;BR /&gt;
       | rename host as "Virtual Machine" &lt;BR /&gt;
       | sort- "Average Usage"&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:57:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309587#M92867</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2020-09-29T17:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309588#M92868</link>
      <description>&lt;P&gt;So you're saying if you run following, you get ~18000 for value in column &lt;CODE&gt;days&lt;/CODE&gt;?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=ProcessStart OR sourcetype=ProcessEnd 
   | eval start=if(sourcetype="ProcessStart",_time,null())
   | eval end=if(sourcetype="ProcessEnd",_time,null())
   | stats values(start) as _time values(end) as end by host RunID
   | eval duration=end-_time | bucket span=1d _time
   | stats sum(duration) AS Duration by _time host 
   | stats sum(Duration) as "Average Usage" dc(_time) as days by host 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In line 4, try to replace the &lt;CODE&gt;values(&lt;/CODE&gt; function with &lt;CODE&gt;max(&lt;/CODE&gt; for both &lt;CODE&gt;start&lt;/CODE&gt; and &lt;CODE&gt;end&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 17:04:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309588#M92868</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-06T17:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the Average time usage per day when using Transaction and Bin?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309589#M92869</link>
      <description>&lt;P&gt;Thanks @somesoni2. This worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Now all the lines are around 200 days as expected.&lt;BR /&gt;
Thanks again for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 17:17:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-Average-time-usage-per-day-when-using/m-p/309589#M92869</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2018-02-06T17:17:59Z</dc:date>
    </item>
  </channel>
</rss>

