health.asciidoc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. [[cat-health]]
  2. === cat health API
  3. ++++
  4. <titleabbrev>cat health</titleabbrev>
  5. ++++
  6. Returns the health status of a cluster, similar to the <<cluster-health,cluster
  7. health>> API.
  8. [[cat-health-api-request]]
  9. ==== {api-request-title}
  10. `GET /_cat/health`
  11. [[cat-health-api-prereqs]]
  12. ==== {api-prereq-title}
  13. * If the {es} {security-features} are enabled, you must have the `monitor` or
  14. `manage` <<privileges-list-cluster,cluster privilege>> to use this API.
  15. [[cat-health-api-desc]]
  16. ==== {api-description-title}
  17. You can use the cat health API to get the health status of a cluster.
  18. [[timestamp]]
  19. This API is often used to check malfunctioning clusters. To help you
  20. track cluster health alongside log files and alerting systems, the API returns
  21. timestamps in two formats:
  22. * `HH:MM:SS`, which is human-readable but includes no date information.
  23. * {wikipedia}/Unix_time[Unix `epoch` time], which is
  24. machine-sortable and includes date information. This is useful for cluster
  25. recoveries that take multiple days.
  26. You can use the cat health API to verify cluster health across multiple nodes.
  27. See <<cat-health-api-example-across-nodes>>.
  28. You also can use the API to track the recovery of a large cluster
  29. over a longer period of time. See <<cat-health-api-example-large-cluster>>.
  30. [[cat-health-api-query-params]]
  31. ==== {api-query-parms-title}
  32. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=http-format]
  33. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=cat-h]
  34. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=help]
  35. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=cat-s]
  36. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=time]
  37. `ts` (timestamps)::
  38. (Optional, Boolean) If `true`, returns `HH:MM:SS` and
  39. {wikipedia}/Unix_time[Unix `epoch`] timestamps. Defaults to
  40. `true`.
  41. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=cat-v]
  42. [[cat-health-api-example]]
  43. ==== {api-examples-title}
  44. [[cat-health-api-example-timestamp]]
  45. ===== Example with a timestamp
  46. By default, the cat health API returns `HH:MM:SS` and
  47. {wikipedia}/Unix_time[Unix `epoch`] timestamps. For example:
  48. [source,console,id=cat-health-example]
  49. --------------------------------------------------
  50. GET /_cat/health?v=true
  51. --------------------------------------------------
  52. // TEST[s/^/PUT my-index-000001\n{"settings":{"number_of_replicas": 0}}\n/]
  53. The API returns the following response:
  54. [source,txt]
  55. --------------------------------------------------
  56. epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
  57. 1475871424 16:17:04 elasticsearch green 1 1 1 1 0 0 0 0 - 100.0%
  58. --------------------------------------------------
  59. // TESTRESPONSE[s/1475871424 16:17:04/\\d+ \\d+:\\d+:\\d+/]
  60. // TESTRESPONSE[s/elasticsearch/[^ ]+/ s/0 -/\\d+ (-|\\d+(\\.\\d+)?[ms]+)/ non_json]
  61. [[cat-health-api-example-no-timestamp]]
  62. ===== Example without a timestamp
  63. You can use the `ts` (timestamps) parameter to disable timestamps. For example:
  64. [source,console,id=cat-health-no-timestamp-example]
  65. --------------------------------------------------
  66. GET /_cat/health?v=true&ts=false
  67. --------------------------------------------------
  68. // TEST[s/^/PUT my-index-000001\n{"settings":{"number_of_replicas": 0}}\n/]
  69. The API returns the following response:
  70. [source,txt]
  71. --------------------------------------------------
  72. cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
  73. elasticsearch green 1 1 1 1 0 0 0 0 - 100.0%
  74. --------------------------------------------------
  75. // TESTRESPONSE[s/elasticsearch/[^ ]+/ s/0 -/\\d+ (-|\\d+(\\.\\d+)?[ms]+)/ non_json]
  76. [[cat-health-api-example-across-nodes]]
  77. ===== Example across nodes
  78. You can use the cat health API to verify the health of a cluster across nodes.
  79. For example:
  80. [source,sh]
  81. --------------------------------------------------
  82. % pssh -i -h list.of.cluster.hosts curl -s localhost:9200/_cat/health
  83. [1] 20:20:52 [SUCCESS] es3.vm
  84. 1384309218 18:20:18 foo green 3 3 3 3 0 0 0 0
  85. [2] 20:20:52 [SUCCESS] es1.vm
  86. 1384309218 18:20:18 foo green 3 3 3 3 0 0 0 0
  87. [3] 20:20:52 [SUCCESS] es2.vm
  88. 1384309218 18:20:18 foo green 3 3 3 3 0 0 0 0
  89. --------------------------------------------------
  90. // NOTCONSOLE
  91. [[cat-health-api-example-large-cluster]]
  92. ===== Example with a large cluster
  93. You can use the cat health API to track the recovery of a large cluster over a
  94. longer period of time. You can do this by including the cat health API request
  95. in a delayed loop. For example:
  96. [source,sh]
  97. --------------------------------------------------
  98. % while true; do curl localhost:9200/_cat/health; sleep 120; done
  99. 1384309446 18:24:06 foo red 3 3 20 20 0 0 1812 0
  100. 1384309566 18:26:06 foo yellow 3 3 950 916 0 12 870 0
  101. 1384309686 18:28:06 foo yellow 3 3 1328 916 0 12 492 0
  102. 1384309806 18:30:06 foo green 3 3 1832 916 4 0 0
  103. ^C
  104. --------------------------------------------------
  105. // NOTCONSOLE
  106. In this example, the recovery took roughly six minutes, from `18:24:06` to
  107. `18:30:06`. If this recovery took hours, you could continue to monitor the
  108. number of `UNASSIGNED` shards, which should drop. If the number of `UNASSIGNED`
  109. shards remains static, it would indicate an issue with the cluster recovery.