<?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: Best way to format out time field for average time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Best-way-to-format-out-time-field-for-average-time/m-p/498482#M138891</link>
    <description>&lt;P&gt;you are trying to perform a statistical function &lt;CODE&gt;avg&lt;/CODE&gt; on field that contains strings: &lt;CODE&gt;2m47.012s&lt;/CODE&gt;&lt;BR /&gt;
there are many ways to approach this challenge, here is one using &lt;CODE&gt;rex&lt;/CODE&gt; and &lt;CODE&gt;eval&lt;/CODE&gt; to create an integer for seconds:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1
| eval runtime="2m47.012s,4m4.912s,12m7.020s,0m9.999s,0m0.712s,3m7.012s,14m4.920s,1m17.029s,0m4.880s,0m0.001s"
| makemv delim="," runtime
| mvexpand runtime
| streamstats count as event_count
| eval _time = _time - event_count * 1000
| rename COMMENT as "the above generates data with different time for timechart, below is the solution" 
| rex field=runtime "(?&amp;lt;minutes&amp;gt;\d+)m(?&amp;lt;seconds&amp;gt;\d+).(?&amp;lt;miliseconds&amp;gt;\d+)"
| eval min_to_sec = minutes * 60
| eval mili_to_sec = exact(miliseconds / 1000)
| eval total_runtime_seconds = exact(seconds + min_to_sec + mili_to_sec)
| timechart span=3000s avg(total_runtime_seconds) as avg_run_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
    <pubDate>Mon, 07 Oct 2019 17:06:29 GMT</pubDate>
    <dc:creator>adonio</dc:creator>
    <dc:date>2019-10-07T17:06:29Z</dc:date>
    <item>
      <title>Best way to format out time field for average time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Best-way-to-format-out-time-field-for-average-time/m-p/498481#M138890</link>
      <description>&lt;P&gt;I am using the linux time command to see how long it takes to run a process.&lt;/P&gt;

&lt;P&gt;My logs show as runtime=0m0.000s&lt;/P&gt;

&lt;P&gt;So example would be runtime=2m47.012s&lt;/P&gt;

&lt;P&gt;What is the best way to parse the output that the command "time provides" to be able to get a time chart of the results?&lt;/P&gt;

&lt;P&gt;I tried just doing a timechart, but with no results of the actual time above.&lt;BR /&gt;
index=metrics process=dailybackup&lt;BR /&gt;
|  timechart span=4h avg(runtime)&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 13:50:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Best-way-to-format-out-time-field-for-average-time/m-p/498481#M138890</guid>
      <dc:creator>agentguerry</dc:creator>
      <dc:date>2019-10-07T13:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to format out time field for average time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Best-way-to-format-out-time-field-for-average-time/m-p/498482#M138891</link>
      <description>&lt;P&gt;you are trying to perform a statistical function &lt;CODE&gt;avg&lt;/CODE&gt; on field that contains strings: &lt;CODE&gt;2m47.012s&lt;/CODE&gt;&lt;BR /&gt;
there are many ways to approach this challenge, here is one using &lt;CODE&gt;rex&lt;/CODE&gt; and &lt;CODE&gt;eval&lt;/CODE&gt; to create an integer for seconds:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1
| eval runtime="2m47.012s,4m4.912s,12m7.020s,0m9.999s,0m0.712s,3m7.012s,14m4.920s,1m17.029s,0m4.880s,0m0.001s"
| makemv delim="," runtime
| mvexpand runtime
| streamstats count as event_count
| eval _time = _time - event_count * 1000
| rename COMMENT as "the above generates data with different time for timechart, below is the solution" 
| rex field=runtime "(?&amp;lt;minutes&amp;gt;\d+)m(?&amp;lt;seconds&amp;gt;\d+).(?&amp;lt;miliseconds&amp;gt;\d+)"
| eval min_to_sec = minutes * 60
| eval mili_to_sec = exact(miliseconds / 1000)
| eval total_runtime_seconds = exact(seconds + min_to_sec + mili_to_sec)
| timechart span=3000s avg(total_runtime_seconds) as avg_run_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 17:06:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Best-way-to-format-out-time-field-for-average-time/m-p/498482#M138891</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-10-07T17:06:29Z</dc:date>
    </item>
  </channel>
</rss>

