Splunk Search

How to sum time duration from value format "1d hh:mm:ss"?

trengginas
Engager

hi am newbie

I have a duration time value with the format "1d hh:mm:ss"
but I haven't gotten a thread that discusses summing with that format.

Example:
hostname=hostA outage="1d 21:49:48"
hostname=hostA outage="10:30:50"
i want the result can be like that > total outage = 2d 08:20:38 or 56:20:38

happy for the help
thanks

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

You should convert your outage strings to seconds, sum them, then convert them back to durations

| rex field=outage "((((?<days>\d+)d )?(?<hours>\d+):)?(?<mins>\d+):)?(?<secs>\d+)"
| fillnull value=0 days hours mins secs
| eval outage_seconds=(((((days * 24) + hours) * 60) + mins) * 60) + secs
| stats sum(outage_seconds) as total_outage
| eval outage_total=replace(tostring(total_outage,"duration"), "\+", "d ")

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

You should convert your outage strings to seconds, sum them, then convert them back to durations

| rex field=outage "((((?<days>\d+)d )?(?<hours>\d+):)?(?<mins>\d+):)?(?<secs>\d+)"
| fillnull value=0 days hours mins secs
| eval outage_seconds=(((((days * 24) + hours) * 60) + mins) * 60) + secs
| stats sum(outage_seconds) as total_outage
| eval outage_total=replace(tostring(total_outage,"duration"), "\+", "d ")

trengginas
Engager

Big Thanks ITWhisperer

its work for me, i must learn rex specialy 😅

btw sorry my translate english 😁

0 Karma
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!

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...