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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...