health.asciidoc 5.2 KB

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