# Parsing execution metrics which are represented as TimeSpan

**URL:** <https://discuss.elastic.co/t/parsing-execution-metrics-which-are-represented-as-timespan/2274>\
**Category:** Logstash\
**Created:** [June 10, 2015, 7:12am UTC](https://discuss.elastic.co/t/parsing-execution-metrics-which-are-represented-as-timespan/2274 "2015-06-10T07:12:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxcherednik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxcherednik/32/590_2.png) [@maxcherednik](https://discuss.elastic.co/u/maxcherednik)\
**Post date:** [June 10, 2015, 7:12am UTC](https://discuss.elastic.co/t/parsing-execution-metrics-which-are-represented-as-timespan/2274/1 "2015-06-10T07:12:43Z")

</div>

Hi,

I've got a log file with rows like this: Action1 took: 00:00:00.0320605  
I would like to parse it and output to elasticsearh.  
As far as I know there is no such type like TimeSpan, so I need to convert it to int or float.

I think I've got 2 options here:

1. Change the logging and print number of seconds as well
2. Convert the existing TimeSpan to seconds representation using the logstash filters

How can I achieve this?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 10, 2015, 7:30pm UTC](https://discuss.elastic.co/t/parsing-execution-metrics-which-are-represented-as-timespan/2274/2 "2015-06-10T19:30:34Z")

</div>

You can use a grok filter to extract the hours, minutes, and seconds into separate fields, then use a simple ruby filter to combine them. Untested:

```
filter {
  grok {
    match => ["timespan", "%{INT:hours}:%{INT:MINUTES}:%{NUMBER:seconds}"
  }
  ruby {
    code => "
      event['elapsed'] = 3600 * event['hours'].to_f + 60 * event['minutes'].to_f + event['seconds'].to_f
    "
    remove_field => ["hours", "minutes", "seconds"]
  }
}
```

---

<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:** [July 6, 2017, 5:37am UTC](https://discuss.elastic.co/t/parsing-execution-metrics-which-are-represented-as-timespan/2274/3 "2017-07-06T05:37:48Z")

</div>


