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
Get Updates on the Splunk Community!

Improve Your Security Posture

Watch NowImprove Your Security PostureCustomers are at the center of everything we do at Splunk and security ...

Maximize the Value from Microsoft Defender with Splunk

 Watch NowJoin Splunk and Sens Consulting for this Security Edition Tech TalkWho should attend:  Security ...

This Week's Community Digest - Splunk Community Happenings [6.27.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...