Elasticsearch 6 クラスタヘルスチェックAPI
クラスタヘルスチェックAPIを使ってヘルスチェックができます。Elasticsearch 6.xのヘルスチェックは、以下のようになります。
curl http://localhost:9200/_cluster/health
参考
実行すると、以下のようになります。 クラスタの状態は、status の値でわかり、green なら正常です。 yellow や red なら問題があります。 ただし、1つのノードだけでレプリカを持っていない場合は、レプリカを配置するノードが無いため green にならず、yellow か red のどちらかにしかなりません。
$ curl http://localhost:9200/_cluster/health?pretty
{
"cluster_name" : "elasticsearch",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 6,
"active_shards" : 6,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 6,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 50.0
}
Pending Task
ヘルスチェックの結果に "number_of_pending_tasks" の項目がありますが、これが0以外の場合、未完了のタスクがあります。 その詳細を確認したい場合は、以下を実行します。
curl http://localhost:920/_cluster/pending_tasks
実行すると、以下のようになります。この例では未完了タスクは無しです。
$ curl http://localhost:9200/_cluster/pending_tasks?pretty
{
"tasks" : [ ]
}