stats.asciidoc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. [role="xpack"]
  2. [[watcher-api-stats]]
  3. === Get {watcher} stats API
  4. [subs="attributes"]
  5. ++++
  6. <titleabbrev>Get {watcher} stats</titleabbrev>
  7. ++++
  8. Retrieves the current {watcher} metrics.
  9. [[watcher-api-stats-request]]
  10. ==== {api-request-title}
  11. `GET _watcher/stats` +
  12. `GET _watcher/stats/<metric>`
  13. [[watcher-api-stats-prereqs]]
  14. ==== {api-prereq-title}
  15. * You must have `manage_watcher` or `monitor_watcher` cluster privileges to use
  16. this API. For more information, see
  17. <<security-privileges>>.
  18. //[[watcher-api-stats-desc]]
  19. //==== {api-description-title}
  20. [[watcher-api-stats-path-params]]
  21. ==== {api-path-parms-title}
  22. `emit_stacktraces`::
  23. (Optional, Boolean) Defines whether stack traces are generated for each watch
  24. that is running. The default value is `false`.
  25. `<metric>`::
  26. (Optional, enum) Defines which additional metrics are included in the response.
  27. `current_watches`::: Includes the current executing watches in the response.
  28. `queued_watches`::: Includes the watches queued for execution in the response.
  29. `_all`::: Includes all metrics in the response.
  30. //[[watcher-api-stats-query-params]]
  31. //==== {api-query-parms-title}
  32. //[[watcher-api-stats-request-body]]
  33. //==== {api-request-body-title}
  34. [[watcher-api-stats-response-body]]
  35. ==== {api-response-body-title}
  36. This API always returns basic metrics. You retrieve more metrics by using
  37. the `metric` parameter.
  38. `current_watches`::
  39. (list) The current executing watches metric gives insight into the watches
  40. that are currently being executed by {watcher}. Additional information is
  41. shared per watch that is currently executing. This information includes the
  42. `watch_id`, the time its execution started and its current execution phase.
  43. To include this metric, the `metric` option should be set to `current_watches`
  44. or `_all`. In addition you can also specify the `emit_stacktraces=true`
  45. parameter, which adds stack traces for each watch that is being executed. These
  46. stack traces can give you more insight into an execution of a watch.
  47. `queued_watches`::
  48. (list) {watcher} moderates the execution of watches such that their execution
  49. won't put too much pressure on the node and its resources. If too many watches
  50. trigger concurrently and there isn't enough capacity to execute them all, some
  51. of the watches are queued, waiting for the current executing watches to finish
  52. their execution. The queued watches metric gives insight on these queued
  53. watches.
  54. To include this metric, the `metric` option should include `queued_watches` or
  55. `_all`.
  56. //[[watcher-api-stats-response-codes]]
  57. //==== {api-response-codes-title}
  58. [[watcher-api-stats-example]]
  59. ==== {api-examples-title}
  60. The following example calls the `stats` API to retrieve basic metrics:
  61. [source,console]
  62. --------------------------------------------------
  63. GET _watcher/stats
  64. --------------------------------------------------
  65. A successful call returns a JSON structure similar to the following example:
  66. [source,js]
  67. --------------------------------------------------
  68. {
  69. "watcher_state": "started", <1>
  70. "watch_count": 1, <2>
  71. "execution_thread_pool": {
  72. "size": 1000, <3>
  73. "max_size": 1 <4>
  74. }
  75. }
  76. --------------------------------------------------
  77. <1> The current state of watcher, which can be `started`, `starting`, or `stopped`.
  78. <2> The number of watches currently registered.
  79. <3> The number of watches that were triggered and currently queued for execution.
  80. <4> The largest size of the execution thread pool, which indicates the largest
  81. number of concurrent executing watches.
  82. The following example specifies the `metric` option as a query string argument
  83. and will include the basic metrics and metrics about the current executing watches:
  84. [source,console]
  85. --------------------------------------------------
  86. GET _watcher/stats?metric=current_watches
  87. --------------------------------------------------
  88. The following example specifies the `metric` option as part of the url path:
  89. [source,console]
  90. --------------------------------------------------
  91. GET _watcher/stats/current_watches
  92. --------------------------------------------------
  93. The following snippet shows an example of a successful JSON response that
  94. captures a watch in execution:
  95. [source,js]
  96. --------------------------------------------------
  97. {
  98. "watcher_state": "started",
  99. "watch_count": 2,
  100. "execution_thread_pool": {
  101. "queue_size": 1000,
  102. "max_size": 20
  103. },
  104. "current_watches": [ <1>
  105. {
  106. "watch_id": "slow_condition", <2>
  107. "watch_record_id": "slow_condition_3-2015-05-13T07:42:32.179Z", <3>
  108. "triggered_time": "2015-05-12T11:53:51.800Z", <4>
  109. "execution_time": "2015-05-13T07:42:32.179Z", <5>
  110. "execution_phase": "condition" <6>
  111. }
  112. ]
  113. }
  114. --------------------------------------------------
  115. <1> A list of all the watches that are currently being executed by {watcher}.
  116. When no watches are currently executing, an empty array is returned. The
  117. captured watches are sorted by execution time in descending order. Thus the
  118. longest running watch is always at the top.
  119. <2> The id of the watch being executed.
  120. <3> The id of the watch record.
  121. <4> The time the watch was triggered by the trigger engine.
  122. <5> The time the watch was executed. This is just before the input is being
  123. executed.
  124. <6> The current watch execution phase. Can be `input`, `condition` `actions`,
  125. `awaits_execution`, `started`, `watch_transform`, `aborted`, `finished`.
  126. The following example specifies the `queued_watches` metric option and includes
  127. both the basic metrics and the queued watches:
  128. [source,console]
  129. --------------------------------------------------
  130. GET _watcher/stats/queued_watches
  131. --------------------------------------------------
  132. An example of a successful JSON response that captures a watch in execution:
  133. [source,js]
  134. --------------------------------------------------
  135. {
  136. "watcher_state": "started",
  137. "watch_count": 10,
  138. "execution_thread_pool": {
  139. "queue_size": 1000,
  140. "max_size": 20
  141. },
  142. "queued_watches": [ <1>
  143. {
  144. "watch_id": "slow_condition4", <2>
  145. "watch_record_id": "slow_condition4_223-2015-05-21T11:59:59.811Z", <3>
  146. "triggered_time": "2015-05-21T11:59:59.811Z", <4>
  147. "execution_time": "2015-05-21T11:59:59.811Z" <5>
  148. },
  149. ...
  150. ]
  151. }
  152. --------------------------------------------------
  153. <1> A list of all watches that are currently queued for execution. When no
  154. watches are queued, an empty array is returned.
  155. <2> The id of the watch queued for execution.
  156. <3> The id of the watch record.
  157. <4> The time the watch was triggered by the trigger engine.
  158. <5> The time the watch was went into a queued state.