Splunk Search

calculate sum of duration

g_paternicola
Path Finder

Hi everyone,

I have calculated a duration field like this for example

Duration
00:22:02
00:19:26
00:04:26
00:20:16
00:16:47

with this search

my_search | convert num("Duration") | stats sum("Duration") as "Total" | eval "Total"=tostring($Total$,"duration")


and I have the result of  this in a total of all my durations

5+17:02:53

I there a way to convert or transform this result in 
5 days
17 hours
02 minutes
53 seconds

or something like this would also be great:

5 days 17:02:53'

Thank you very much!

Labels (4)
Tags (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Split into two rex in case the duration is not more than 1 day.

| rex field=Total mode=sed "s/\+/ days /g"
| rex field=Total mode=sed "s/(\d\d):(\d\d):(\d\d)/\1 hours \2 minutes \3 seconds/g"

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

There is no built-in function to do that so you'll have to do it manually.  Start with a simple replace:

| replace "+" with " days " in Total

For something a little more complex, try rex:

| rex field=Total "(?:(?<days>\d+)\+)?(?<hours>\d+):(?<minutes>\d+):(?<seconds>\d+)"
| eval Total = if(isnull(days),0,days)." days ".hours." hours ".minutes." minutes ".seconds." seconds"

 

---
If this reply helps you, Karma would be appreciated.

ITWhisperer
SplunkTrust
SplunkTrust

Split into two rex in case the duration is not more than 1 day.

| rex field=Total mode=sed "s/\+/ days /g"
| rex field=Total mode=sed "s/(\d\d):(\d\d):(\d\d)/\1 hours \2 minutes \3 seconds/g"
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...