<?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 Can I use Stats Avg() On a Datetime Field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-Can-I-use-Stats-Avg-On-a-Datetime-Field/m-p/143746#M39947</link>
    <description>&lt;P&gt;I have this indexed field which is read by splunk as a string,  I need the average length, but the data has no Day, month or year,  just time. &lt;/P&gt;

&lt;P&gt;Example data :&lt;BR /&gt;
03:20:15&lt;BR /&gt;
02:45:07&lt;BR /&gt;
03:12:00&lt;BR /&gt;
04:05:23&lt;/P&gt;

&lt;P&gt;How do I convert these so Splunk can get the average?? &lt;/P&gt;

&lt;P&gt;Thanks in advance! &lt;/P&gt;</description>
    <pubDate>Sun, 26 Jul 2015 15:49:42 GMT</pubDate>
    <dc:creator>vtsguerrero</dc:creator>
    <dc:date>2015-07-26T15:49:42Z</dc:date>
    <item>
      <title>How Can I use Stats Avg() On a Datetime Field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Can-I-use-Stats-Avg-On-a-Datetime-Field/m-p/143746#M39947</link>
      <description>&lt;P&gt;I have this indexed field which is read by splunk as a string,  I need the average length, but the data has no Day, month or year,  just time. &lt;/P&gt;

&lt;P&gt;Example data :&lt;BR /&gt;
03:20:15&lt;BR /&gt;
02:45:07&lt;BR /&gt;
03:12:00&lt;BR /&gt;
04:05:23&lt;/P&gt;

&lt;P&gt;How do I convert these so Splunk can get the average?? &lt;/P&gt;

&lt;P&gt;Thanks in advance! &lt;/P&gt;</description>
      <pubDate>Sun, 26 Jul 2015 15:49:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Can-I-use-Stats-Avg-On-a-Datetime-Field/m-p/143746#M39947</guid>
      <dc:creator>vtsguerrero</dc:creator>
      <dc:date>2015-07-26T15:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I use Stats Avg() On a Datetime Field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Can-I-use-Stats-Avg-On-a-Datetime-Field/m-p/143747#M39948</link>
      <description>&lt;P&gt;May be do an eval and convert them to total seconds into a new field.. and do average on the new field.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jul 2015 16:26:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Can-I-use-Stats-Avg-On-a-Datetime-Field/m-p/143747#M39948</guid>
      <dc:creator>pradeepkumarg</dc:creator>
      <dc:date>2015-07-26T16:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I use Stats Avg() On a Datetime Field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Can-I-use-Stats-Avg-On-a-Datetime-Field/m-p/143748#M39949</link>
      <description>&lt;P&gt;What function could I use to convert em with an eval?  I mean,  I dont have the full date...&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jul 2015 17:30:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Can-I-use-Stats-Avg-On-a-Datetime-Field/m-p/143748#M39949</guid>
      <dc:creator>vtsguerrero</dc:creator>
      <dc:date>2015-07-26T17:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I use Stats Avg() On a Datetime Field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Can-I-use-Stats-Avg-On-a-Datetime-Field/m-p/143749#M39950</link>
      <description>&lt;P&gt;One method could be to use the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.4/SearchReference/convert"&gt;convert&lt;/A&gt; command to change the field from a duration into to seconds, then average with some form of stats, and if necessary use the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.4/SearchReference/CommonEvalFunctions"&gt;tostring&lt;/A&gt; function in an &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.4/SearchReference/eval"&gt;eval&lt;/A&gt; to change back to duration format.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | convert dur2sec(field) | stats avg(field) as field | eval field=tostring(round(field),"duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now with any solution there are some assumptions of your data, with this convert method, it assumes that&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;No fractional seconds are present e.g. "01:02:03.456" would not work&lt;/LI&gt;
&lt;LI&gt;Days are specified as "D+" e.g. "1+0:0:1" will work but "1:0:0:1" will not&lt;/LI&gt;
&lt;LI&gt;Hours and minutes respect their respective moduli (0-23 hours, 0-59 minutes)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;If your data doesn't conform to this, then you could craft your own regular expression and use &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.4/SearchReference/rex"&gt;rex&lt;/A&gt; command to pull out the pieces and use an eval to combine into seconds:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=field "^(?&amp;lt;dur_h&amp;gt;\d+):(?&amp;lt;dur_m&amp;gt;\d+):(?&amp;lt;dur_s&amp;gt;\d+(?:\.\d+)?)$" | eval dur = (dur_h*60 + dur_m)*60 + dur_s | stats avg(dur) as field 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Jul 2015 18:38:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Can-I-use-Stats-Avg-On-a-Datetime-Field/m-p/143749#M39950</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-07-26T18:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I use Stats Avg() On a Datetime Field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Can-I-use-Stats-Avg-On-a-Datetime-Field/m-p/143750#M39951</link>
      <description>&lt;P&gt;Thanks a lot @acharlieh ♦ !&lt;BR /&gt;
Worked perfectly!&lt;BR /&gt;
Just tryin' now to get the difference from the last head 1 event duration to the average duration.&lt;BR /&gt;
With the average and the last event I shall get the deviation to generate a red, yellow or green status.&lt;BR /&gt;
Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2015 13:24:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Can-I-use-Stats-Avg-On-a-Datetime-Field/m-p/143750#M39951</guid>
      <dc:creator>vtsguerrero</dc:creator>
      <dc:date>2015-07-27T13:24:22Z</dc:date>
    </item>
  </channel>
</rss>

