<?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 take an average of a time log? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/604999#M210410</link>
    <description>&lt;P&gt;Count is easy - splunk can count anything &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;max probably shows you lexicographic max. If you have leading zeros it will accidentally be the same as arithmetic max but if you didn't, 012:34:56 would be "less" than 9:12:23.&lt;/P&gt;&lt;P&gt;avg doesn't work because you can't calculate numeric functions on strings. You have to parse the strings to numbers first.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jul 2022 19:08:31 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2022-07-08T19:08:31Z</dc:date>
    <item>
      <title>How to take an average of a time log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/604995#M210409</link>
      <description>&lt;P&gt;Hello peeps,&lt;/P&gt;&lt;P&gt;Currently I have a list of processing times. And I am trying to create a dashboard that shows the average time, max time, and the count of how many times that action is processed.&lt;/P&gt;&lt;P&gt;index=IndexA | stats avg(cTotal) max(cTotal) count(cTotal) by name | sort 10 -count(cTotal)&lt;/P&gt;&lt;P&gt;Totaltime is a given header and an example is&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the script, I get accurate results for count and max, but the avg is not currently working.&lt;/P&gt;&lt;P&gt;I'm thinking it's because of the time string (hours, min, sec, milisec) but if anyone has any advice on how to make the average work, I would love to hear it!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 23:02:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/604995#M210409</guid>
      <dc:creator>amaralt808</dc:creator>
      <dc:date>2023-09-12T23:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to take an average of a time log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/604999#M210410</link>
      <description>&lt;P&gt;Count is easy - splunk can count anything &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;max probably shows you lexicographic max. If you have leading zeros it will accidentally be the same as arithmetic max but if you didn't, 012:34:56 would be "less" than 9:12:23.&lt;/P&gt;&lt;P&gt;avg doesn't work because you can't calculate numeric functions on strings. You have to parse the strings to numbers first.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 19:08:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/604999#M210410</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-07-08T19:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to take an average of a time log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605001#M210411</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;That makes sense, do you have a suggestion about how I can pass that time format as a string?&lt;/P&gt;&lt;P&gt;I tried this code previously,&lt;/P&gt;&lt;P&gt;index=IndexA&lt;BR /&gt;| eval cTotal = strftime(strptime(totaltime, "%H:%M:%S.%f"), "%S.%f")&lt;BR /&gt;| stats avg(cTotal) max(cTotal) count(cTotal) by name&lt;BR /&gt;| sort 10 -count(cTotal)&lt;/P&gt;&lt;P&gt;But I realized that the cTotal only has the seconds and miliseconds.&lt;/P&gt;&lt;P&gt;Is there like a best practice to convert&amp;nbsp;"%H:%M:%S.%f" format into a string?&lt;/P&gt;&lt;P&gt;Sorry about this, I am beginning my journey into Splunk&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 19:15:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605001#M210411</guid>
      <dc:creator>amaralt808</dc:creator>
      <dc:date>2022-07-08T19:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to take an average of a time log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605009#M210412</link>
      <description>&lt;P&gt;You had a pretty decent idea with strptime. But unnecessarily you're trying to render it back to string with strftime. At this point just gomwith strptime and let it be a number.&lt;/P&gt;&lt;P&gt;Then you can do your calculations (max, avg) and only at the end do strftime/convert/tostring to get a human-readable string.&lt;/P&gt;&lt;P&gt;The rule of thumb is that if you're doing anything with time, you want to have it as a number of seconds (with absolute timestamps as number of seconds since epoch, with duration-oriented fields, just duration expressed in seconds). This way you can easily manipulate those fields.&lt;/P&gt;&lt;P&gt;Only at the end - for presentation - you might want to render them to strings.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 19:49:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605009#M210412</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-07-08T19:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to take an average of a time log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605019#M210415</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;A href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884" target="_blank"&gt;@PickleRick&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;I have another question, I don't know if I did this correctly.&lt;/P&gt;&lt;P&gt;Here is my code&lt;BR /&gt;index=IndexA&lt;BR /&gt;| eval cTotal = strptime(totaltime, "%H:%M:%S.%f")&lt;BR /&gt;| stats avg(cTotal) max(cTotal) count(cTotal) by name&lt;BR /&gt;| sort 10 -count(cTotal)&lt;/P&gt;&lt;P&gt;Here are my results with the strip time and the same process in a different search with the actual time.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="amaralt808_0-1657313124967.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/20471iC0C5D97DE9D0C097/image-size/medium?v=v2&amp;amp;px=400" role="button" title="amaralt808_0-1657313124967.png" alt="amaralt808_0-1657313124967.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The times in the new search don't seem to match.&lt;BR /&gt;Any help would be appreciated&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 20:45:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605019#M210415</guid>
      <dc:creator>amaralt808</dc:creator>
      <dc:date>2022-07-08T20:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to take an average of a time log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605027#M210419</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="amaralt808_1-1657315635801.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/20473i46015FA80858B410/image-size/medium?v=v2&amp;amp;px=400" role="button" title="amaralt808_1-1657315635801.png" alt="amaralt808_1-1657315635801.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 21:27:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605027#M210419</guid>
      <dc:creator>amaralt808</dc:creator>
      <dc:date>2022-07-08T21:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to take an average of a time log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605068#M210434</link>
      <description>&lt;P&gt;Indeed. I forgot that if you don't have the date part specified in your strptimed time string, splunk will assume "today". Which makes the values quite large &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm not sure there is a ready-made function for converting string-expressed durations to number. You might want to split the string by colon and multiply each number by 60 and 3600 respectively.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2022 09:33:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605068#M210434</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-07-10T09:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to take an average of a time log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605329#M210496</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;I followed your advice and manually split them up by doing math.&lt;/P&gt;&lt;P&gt;Here is the code that ended up working.&lt;BR /&gt;&lt;BR /&gt;| eval cTotal = strptime(totaltime, "%H:%M:%S.%f")&lt;BR /&gt;| rex field=totaltime "(?&amp;lt;totaltimeH&amp;gt;\d+):(?&amp;lt;totaltimeM&amp;gt;\d+):(?&amp;lt;totaltimeS&amp;gt;.*)" | eval totaltime=totaltimeS + 60 * (totaltimeM + 60 * (totaltimeH)) |&lt;BR /&gt;stats avg(totaltime) max(totaltime) count(totaltime) by name&lt;BR /&gt;| sort 10 -count(totaltime)&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2022 18:47:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-take-an-average-of-a-time-log/m-p/605329#M210496</guid>
      <dc:creator>amaralt808</dc:creator>
      <dc:date>2022-07-12T18:47:48Z</dc:date>
    </item>
  </channel>
</rss>

