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!

Detecting Brute Force Account Takeover Fraud with Splunk

This article is the second in a three-part series exploring advanced fraud detection techniques using Splunk. ...

Buttercup Games: Further Dashboarding Techniques (Part 9)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...

Buttercup Games: Further Dashboarding Techniques (Part 8)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...