<?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 calculate Average duration based on Timestamp? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198526#M39345</link>
    <description>&lt;P&gt;Try this (@Mus solution with output formatting)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your base search  
| eval DURATION=ltrim(DURATION, "ms")
|timechart span=1h avg(DURATION) as Duration
| eval Date=strftime(_time,"%m/%d/%Y") | eval Period=strftime(_time,"%H:%M:%S %p")." - ".strftime(relative_time(_time,"+1h")-1,"%H:%M:%S %p") | table Date, Period,Duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 16 Jun 2014 17:22:30 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2014-06-16T17:22:30Z</dc:date>
    <item>
      <title>How to calculate Average duration based on Timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198524#M39343</link>
      <description>&lt;P&gt;My log looks something similar to this. I will have at least 100 different durations per hour. (Duration is the time which is taken to complete one transaction). My requirement is to create a table/chart with the average duration per hour.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Expected&lt;/STRONG&gt;  &lt;/P&gt;

&lt;P&gt;06/09/2014 |  12:00:00 AM - 12:59:59 AM   |  15 ms | i.e (10+20)/2&lt;BR /&gt;&lt;BR /&gt;
06/09/2014 |  01:00:00 AM - 01:59:59 AM   |  20 ms | i.e (20+20+20)/3&lt;BR /&gt;&lt;BR /&gt;
.&lt;BR /&gt;&lt;BR /&gt;
.&lt;BR /&gt;&lt;BR /&gt;
I should get only 24 results always. The time mentioned in log is not the time indexed by Splunk. It comes from the application logs. I tried lot of things but nothing is working. can someone help me in solving the problem. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Log format&lt;/STRONG&gt;  &lt;/P&gt;

&lt;P&gt;MYTIME,DURATION  &lt;/P&gt;

&lt;P&gt;06/09/2014 12:01:16 AM  10ms&lt;BR /&gt;&lt;BR /&gt;
06/09/2014 12:05:51 AM  20ms&lt;BR /&gt;&lt;BR /&gt;
..&lt;BR /&gt;&lt;BR /&gt;
06/09/2014 01:01:16 AM  20ms&lt;BR /&gt;&lt;BR /&gt;
06/09/2014 01:05:51 AM  20ms&lt;BR /&gt;&lt;BR /&gt;
06/09/2014 01:05:51 AM  20ms&lt;BR /&gt;&lt;BR /&gt;
..&lt;BR /&gt;&lt;BR /&gt;
06/09/2014 02:01:11 AM  70ms&lt;BR /&gt;&lt;BR /&gt;
06/09/2014 02:03:11 AM  20ms&lt;BR /&gt;&lt;BR /&gt;
...&lt;BR /&gt;&lt;BR /&gt;
06/09/2014 03:01:14 PM  74ms&lt;BR /&gt;&lt;BR /&gt;
06/09/2014 03:01:16 PM  87ms&lt;BR /&gt;&lt;BR /&gt;
...&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jun 2014 06:47:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198524#M39343</guid>
      <dc:creator>thiagarajan</dc:creator>
      <dc:date>2014-06-16T06:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate Average duration based on Timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198525#M39344</link>
      <description>&lt;P&gt;Hi thiagarajan,&lt;/P&gt;

&lt;P&gt;how about this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search here 
| eval myTime=ltrim(DURATION, "ms")
| timechart span=1h avg(myTime) AS Duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;first you need to trim your duration time to get only numbers, then you can chart it by hour.&lt;/P&gt;

&lt;P&gt;hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jun 2014 08:12:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198525#M39344</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-06-16T08:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate Average duration based on Timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198526#M39345</link>
      <description>&lt;P&gt;Try this (@Mus solution with output formatting)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your base search  
| eval DURATION=ltrim(DURATION, "ms")
|timechart span=1h avg(DURATION) as Duration
| eval Date=strftime(_time,"%m/%d/%Y") | eval Period=strftime(_time,"%H:%M:%S %p")." - ".strftime(relative_time(_time,"+1h")-1,"%H:%M:%S %p") | table Date, Period,Duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Jun 2014 17:22:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198526#M39345</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-06-16T17:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate Average duration based on Timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198527#M39346</link>
      <description>&lt;P&gt;Thank you very much MuS. I'm bit confused here. Whether we have to calculate avg of duration or myTime.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jun 2014 20:46:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198527#M39346</guid>
      <dc:creator>thiagarajan</dc:creator>
      <dc:date>2014-06-17T20:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate Average duration based on Timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198528#M39347</link>
      <description>&lt;P&gt;Thank you somesoni2. I'm bit confused here. Whether we have to calculate avg of duration or myTime.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jun 2014 20:49:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198528#M39347</guid>
      <dc:creator>thiagarajan</dc:creator>
      <dc:date>2014-06-17T20:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate Average duration based on Timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198529#M39348</link>
      <description>&lt;P&gt;I have overwritten the DURATION field with value without ms (see |eval DURATION=...., @Mus has created new field myTime) so average is calculated based on that. &lt;BR /&gt;
The search is creating resultset which can be displayed as chart/table. You would have to select appropriate option to display the data in the format you want.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jun 2014 21:15:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198529#M39348</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-06-17T21:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate Average duration based on Timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198530#M39349</link>
      <description>&lt;P&gt;There is no difference if you use&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search here 
| eval myTime=ltrim(DURATION, "ms")
| timechart span=1h avg(myTime) AS Duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search here 
| eval DURATION=ltrim(DURATION, "ms")
| timechart span=1h avg(DURATION) AS Duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first uses a newly created field and the second always uses &lt;CODE&gt;DURATION&lt;/CODE&gt; as field name.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2014 05:17:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-Average-duration-based-on-Timestamp/m-p/198530#M39349</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-06-18T05:17:11Z</dc:date>
    </item>
  </channel>
</rss>

