Splunk Search

How do I convert duration to minutes

gill1723
Engager

index=main host=10.247.82.1 user=* | rex field=duration "((?\d+)h:)?(?\d+)m:(?\d+)s" | eval duration=duration_second+60*duration_minute+3600*coalesce(duration_hour,0) | stats sum(duration) as total_duration by Username, date_month, date_mday | bin _time span=1d

Results:
date month total duration
april 24 2657

Tags (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Try this.

index=main host=10.247.82.1 user=* | rex field=duration "((?<duration_hour>\d+)h:)?(?<duration_minute>\d+)m:(?<duration_second>\d+)s" | eval duration=duration_second+60*duration_minute+3600*coalesce(duration_hour,0) | stats sum(duration) as total_duration by Username, date_month, date_mday | bin _time span=1d | eval total_duration=tostring(total_duration, "duration")
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Try this.

index=main host=10.247.82.1 user=* | rex field=duration "((?<duration_hour>\d+)h:)?(?<duration_minute>\d+)m:(?<duration_second>\d+)s" | eval duration=duration_second+60*duration_minute+3600*coalesce(duration_hour,0) | stats sum(duration) as total_duration by Username, date_month, date_mday | bin _time span=1d | eval total_duration=tostring(total_duration, "duration")
---
If this reply helps you, Karma would be appreciated.

rbansql104
New Member

how can I declare a metrics in which I have the data like 30 days 10 hours 16 minutes have to be converted into seconds?

0 Karma

gill1723
Engager

I get this error when I run that script

⚠ Error in 'rex' command: Encountered the following error while compiling the regex '((?\d+)h:)?(?\d+)m:(?\d+)s': Regex: unrecognized character after (? or (?-

0 Karma

richgalloway
SplunkTrust
SplunkTrust

That's because I copied the search after the forum munged it. I've corrected my answer.

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

gill1723
Engager

This works great thanks a bunch.

0 Karma

gill1723
Engager

I need to convert this to HH:MM:SS

index=main host=10.247.82.1 user=* | rex field=duration "((?\d+)h:)?(?\d+)m:(?\d+)s" | eval duration=duration_second+60*duration_minute+3600*coalesce(duration_hour,0) | stats sum(duration) as total_duration by Username, date_month, date_mday | bin _time span=1d

0 Karma

p_gurav
Champion

Can you try something:

| convert dur2sec(duration) as duration_sec |eval min=duration_sec/60

gill1723
Engager

Sorry I need to convert it to HH:MM:SS

index=main host=10.247.82.1 user=* | rex field=duration "((?\d+)h:)?(?\d+)m:(?\d+)s" | eval duration=duration_second+60*duration_minute+3600*coalesce(duration_hour,0) | stats sum(duration) as total_duration by Username, date_month, date_mday | bin _time span=1d

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...