# Using already provided time period

**URL:** <https://discuss.elastic.co/t/using-already-provided-time-period/274299>\
**Category:** Logstash\
**Created:** [May 28, 2021, 8:13am UTC](https://discuss.elastic.co/t/using-already-provided-time-period/274299 "2021-05-28T08:13:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![111238](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111238/32/57619_2.png) [@111238](https://discuss.elastic.co/u/111238)\
**Post date:** [May 28, 2021, 8:13am UTC](https://discuss.elastic.co/t/using-already-provided-time-period/274299/1 "2021-05-28T08:13:08Z")

</div>

Hello.

I have a bit of a problem here - i'm reseiving via syslog some data including uptime/downtime periods in format _"HHhr:MMmin:SSsec"_.  
There's no problem parsing it in an object like _"downtime.\<hr/min/sec\>"_, but how do I use it as time units for further aggregations/calculations (for example - total downtime for 24 hours)?

A little example just to clarify:  
Data: `*blabla* was down for 23hrs:59mins:57sec`  
Pattern: `%{NUMBER:f5_downtime.hr}[a-z]*:%{NUMBER:f5_downtime.mins}[a-z]*:%{NUMBER:f5_downtime.secs}[a-z]* `

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [May 28, 2021, 5:03pm UTC](https://discuss.elastic.co/t/using-already-provided-time-period/274299/2 "2021-05-28T17:03:35Z")

</div>

I would use a ruby filter to convert them all to seconds and sum them

```
ruby {
    code => '
        total_downtime = 0
        hrs = event.get("f5_downtime.hr").to_i
        if hrs
            total_downtime += hrs * 3600
        end
        mins = event.get("f5_downtime.mins").to_i
        if mins
            total_downtime += mins * 60
        end
        secs = event.get("f5_downtime.secs").to_i
        if secs
            total_downtime += secs
        end
        event.set("f5_downtime.total", total_downtime)
    '
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 25, 2021, 5:03pm UTC](https://discuss.elastic.co/t/using-already-provided-time-period/274299/3 "2021-06-25T17:03:41Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
