health.asciidoc 5.2 KB

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