# What is the best way to get execution\_duration?

**URL:** <https://discuss.elastic.co/t/what-is-the-best-way-to-get-execution-duration/44170>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [March 11, 2016, 2:42pm UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-get-execution-duration/44170 "2016-03-11T14:42:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![beckerdo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/beckerdo/32/8355_2.png) [@beckerdo](https://discuss.elastic.co/u/beckerdo)\
**Post date:** [March 11, 2016, 2:42pm UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-get-execution-duration/44170/1 "2016-03-11T14:42:00Z")

</div>

I'd like my watcher result context to contain execution\_duration as well as the execution\_time. Is there any way to extract that from the result? Or perhaps there is a way to grab it from the watcher watch stats?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 13, 2016, 3:32pm UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-get-execution-duration/44170/2 "2016-03-13T15:32:21Z")

</div>

Hey there,

you can use the watch history to find out more about this, see the [Monitoring Watch Exection](https://www.elastic.co/guide/en/watcher/current/watch-history.html) section in our documentation.

If you query the history, you will find a field called `execution_duration`, which is the duration in milliseconds. Looks like this in the `_source`

```json
_source: {
          watch_id: "$WATCH_NAME",
          state: "executed",
          trigger_event: {
            type: "schedule",
            triggered_time: "2016-02-24T23:02:55.540Z",
            schedule: { scheduled_time: "2016-02-24T23:02:55.404Z" }
          },
          input: {
              ...
            }
          },
          result: {
            execution_time: "2016-02-24T23:02:55.540Z",
            execution_duration: 4,
...

```

Hope this helps.

--Alex

---

<div class="post-metadata">

**Author:** ![beckerdo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/beckerdo/32/8355_2.png) [@beckerdo](https://discuss.elastic.co/u/beckerdo)\
**Post date:** [March 14, 2016, 5:49pm UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-get-execution-duration/44170/3 "2016-03-14T17:49:41Z")

</div>

Thanks Alex. This is not as good as having execution\_duration in the watcher resul, as I will likely gave to add an action that queries the watch history, but it does provide a usable solution.

Thanks, beckerdo

---

<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, 1:46pm UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-get-execution-duration/44170/4 "2017-07-06T13:46:34Z")

</div>


