<?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 duration to seconds in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316192#M94651</link>
    <description>&lt;P&gt;I'm attempting to turn the duration of a process in the PS data into just seconds so I can sort appropriately and find the longest running processes for a single host. All of the data is being generated using the Splunk_TA_nix add-on. &lt;/P&gt;

&lt;P&gt;IN this case, the problem seems to be when processes run for longer than 24 hours. The format comes out like this: &lt;CODE&gt;1-05:51:38&lt;/CODE&gt;&lt;BR /&gt;
which I assume splunk is looking for a '+' instead of a '-' for the day count. &lt;/P&gt;

&lt;P&gt;here's my current query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=nix sourcetype=ps 
| convert dur2sec(ELAPSED) as runTime
| stats avg(pctCPU) as CPU avg(pctMEM) as MEM by host pid runTime
| sort - runTime
| eval runTime=tostring(runTime, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gives me an output that looks like this:&lt;BR /&gt;
&lt;IMG src="https://community.splunk.com/storage/temp/211614-pic1.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;If I am to remove all of the conversion syntax, I get entries like this:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/211615-pic2.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;buuuuuttt, I can't sort on it because splunk doesn't recognize this as a field to sort ascending/descending. &lt;/P&gt;

&lt;P&gt;Is there a way to do sort this field, or change it to seconds properly somehow? &lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 15:36:13 GMT</pubDate>
    <dc:creator>tmarlette</dc:creator>
    <dc:date>2020-09-29T15:36:13Z</dc:date>
    <item>
      <title>duration to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316192#M94651</link>
      <description>&lt;P&gt;I'm attempting to turn the duration of a process in the PS data into just seconds so I can sort appropriately and find the longest running processes for a single host. All of the data is being generated using the Splunk_TA_nix add-on. &lt;/P&gt;

&lt;P&gt;IN this case, the problem seems to be when processes run for longer than 24 hours. The format comes out like this: &lt;CODE&gt;1-05:51:38&lt;/CODE&gt;&lt;BR /&gt;
which I assume splunk is looking for a '+' instead of a '-' for the day count. &lt;/P&gt;

&lt;P&gt;here's my current query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=nix sourcetype=ps 
| convert dur2sec(ELAPSED) as runTime
| stats avg(pctCPU) as CPU avg(pctMEM) as MEM by host pid runTime
| sort - runTime
| eval runTime=tostring(runTime, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gives me an output that looks like this:&lt;BR /&gt;
&lt;IMG src="https://community.splunk.com/storage/temp/211614-pic1.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;If I am to remove all of the conversion syntax, I get entries like this:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/211615-pic2.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;buuuuuttt, I can't sort on it because splunk doesn't recognize this as a field to sort ascending/descending. &lt;/P&gt;

&lt;P&gt;Is there a way to do sort this field, or change it to seconds properly somehow? &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:36:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316192#M94651</guid>
      <dc:creator>tmarlette</dc:creator>
      <dc:date>2020-09-29T15:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: duration to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316193#M94652</link>
      <description>&lt;P&gt;You Could do something like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults 
| eval ELAPSED="1-05:00:04 01:23:45 53:21 :17"
| makemv ELAPSED
| mvexpand ELAPSED
| rex field=ELAPSED "^((?&amp;lt;ElapsedDays&amp;gt;\d*)-)?((?&amp;lt;ElapsedHours&amp;gt;\d+):)?(?&amp;lt;ElapsedMinutes&amp;gt;\d+)?:(?&amp;lt;ElapsedSeconds&amp;gt;\d+)"
| eval runtime=86400*Coalesce(ElapsedDays,0) + 3600*Coalesce(ElapsedHours,0) + 60*Coalesce(ElapsedMinutes,0) + 1*Coalesce(ElapsedSeconds,0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Sep 2017 23:00:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316193#M94652</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-09-01T23:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: duration to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316194#M94653</link>
      <description>&lt;P&gt;Exactly how I would have done it, but inside of a macro.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Sep 2017 22:01:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316194#M94653</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-09-03T22:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: duration to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316195#M94654</link>
      <description>&lt;P&gt;@woodcock - what, and make it repeatable and modular?  Where's the fun in that?  I'd much rather code it &lt;BR /&gt;
 from scratch every single time... zzzzz... huh, what was I saying?&lt;/P&gt;

&lt;P&gt;Would you do it with two parameters, the input field and output field, while allowing them to be the same if desired?&lt;/P&gt;

&lt;P&gt;Of course you would.  And the intermediate rex-extract fields would probably be some set of characters that were meaningful but highly unlikely to exist in natural code.  I've seen you use l33t for that purpose before, or just for fun. &lt;/P&gt;</description>
      <pubDate>Sun, 03 Sep 2017 23:56:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316195#M94654</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-09-03T23:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: duration to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316196#M94655</link>
      <description>&lt;P&gt;I tried this, and it does work. The only catch is that my search is exceptionally slow due to the &lt;CODE&gt;|mv&lt;/CODE&gt; commands I suspect. more tinkering....&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 22:07:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316196#M94655</guid>
      <dc:creator>tmarlette</dc:creator>
      <dc:date>2017-09-05T22:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: duration to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316197#M94656</link>
      <description>&lt;P&gt;@tmarlette - sorry I didn't mark it for you - you only need lines 5 and 6.  1 thru 4 were to create test data.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 22:50:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316197#M94656</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-09-05T22:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: duration to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316198#M94657</link>
      <description>&lt;P&gt;yeah, I caught that. It woks fine, it's just pretty slow on my search head is all. Thanks for the help! &lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 15:05:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316198#M94657</guid>
      <dc:creator>tmarlette</dc:creator>
      <dc:date>2017-09-06T15:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: duration to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316199#M94658</link>
      <description>&lt;P&gt;@tmarlette - Hmmm.  I don't see anything in that that should take very long.  &lt;/P&gt;

&lt;P&gt;Okay, there's a possibility that because of the question marks the rex is doing a little extra work backing up. Let's anchor the right side of the field and see if that cuts the time.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex field=ELAPSED "^((?&amp;lt;ElapsedDays&amp;gt;\d*)-)?((?&amp;lt;ElapsedHours&amp;gt;\d+):)?(?&amp;lt;ElapsedMinutes&amp;gt;\d+)?:(?&amp;lt;ElapsedSeconds&amp;gt;\d+)$"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Sep 2017 18:00:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/duration-to-seconds/m-p/316199#M94658</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-09-06T18:00:51Z</dc:date>
    </item>
  </channel>
</rss>

