클러스터 헬스 API (Cluster Health API)
클러스터 헬스 API는 클러스터의 운영 상태를 한눈에 보여주는 개요를 제공해요. OpenSearch는 클러스터 헬스를 샤드의 할당 상태를 나타내는 세 가지 색으로 표현합니다.
- Green (최상): 모든 기본(primary) 샤드와 복제(replica) 샤드가 노드에 할당됐어요. 클러스터가 완전히 정상적으로 운영되고 있어요.
- Yellow: 모든 기본 샤드는 할당됐지만 일부 복제 샤드는 할당되지 않았어요. 클러스터는 운영되지만 완전히 중복(redundant)되지는 않아요.
- Red (최악): 기본 샤드가 하나 이상 할당되지 않았어요. 일부 데이터를 사용할 수 없고, 검색 요청이 불완전한 결과를 반환할 수 있어요. 전체 헬스 상태를 판단할 때는 가장 나쁜 상태가 우선돼요. 여러 인덱스에 대해 헬스를 요청하면 전체 상태는 가장 나쁜 인덱스 상태로 결정되고, 마찬가지로 인덱스의 상태는 가장 나쁜 샤드 상태로 결정됩니다.
출처: OpenSearch 문서
본문
Endpoints
GET /_cluster/health
GET /_cluster/health/{index}
Path parameters
다음 표는 사용 가능한 경로 파라미터를 보여줘요. 모든 경로 파라미터는 선택사항이에요.
| Parameter | Data type | Description | | index | List or String | A comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (*). To target all data streams and indexes, omit this parameter or use * or _all. |
Query parameters
다음 표는 사용 가능한 쿼리 파라미터를 보여줘요. 모든 쿼리 파라미터는 선택사항이에요.
| Parameter | Data type | Description | Default | | awareness_attribute | String | The name of the awareness attribute for which to return the cluster health status (for example, zone). Applicable only if level is set to awareness_attributes. | N/A | | cluster_manager_timeout | String | The amount of time to wait for a response from the cluster manager node. For more information about supported time units, see Common parameters. | N/A | | expand_wildcards | List or String | Specifies the type of index that wildcard expressions can match. Supports comma-separated values. Valid values are: - all: Match any index, including hidden ones. - closed: Match closed, non-hidden indexes. - hidden: Match hidden indexes. Must be combined with open, closed, or both. - none: Wildcard expressions are not accepted. - open: Match open, non-hidden indexes. | open | | level | String | Controls the amount of detail included in the cluster health response. Valid values are: awareness_attributes, cluster, indices, and shards. | cluster | | local | Boolean | Whether to return information from the local node only instead of from the cluster manager node. | false | | timeout | String | The amount of time to wait for a response from the cluster manager node. For more information about supported time units, see Common parameters. | N/A | | wait_for_active_shards | Integer or String or NULL or String | Waits until the specified number of shards is active before returning a response. Use all for all shards. Valid values are: - all: Wait for all shards to be active. | 0 | | wait_for_events | String | Waits until all currently queued events with the given priority are processed. Valid values are: - immediate: Highest priority, processed as soon as possible. - urgent: Very high priority, processed after immediate events. - high: High priority, processed after urgent events. - normal: Default priority, processed after high priority events. - low: Low priority, processed after normal events. - languid: Lowest priority, processed after all other events. | N/A | | wait_for_no_initializing_shards | Boolean | Whether to wait until there are no initializing shards in the cluster. | false | | wait_for_no_relocating_shards | Boolean | Whether to wait until there are no relocating shards in the cluster. | false | | wait_for_nodes | Integer or String | Waits until the specified number of nodes (N) is available. Accepts >=N, <=N, >N, and <N. You can also use ge(N), le(N), gt(N), and lt(N) notation. | N/A | | wait_for_status | String | Waits until the cluster health reaches the specified status or better. Valid values are: green, GREEN, yellow, YELLOW, red, and RED. | N/A | | weights | JSON object | Assigns weights to attributes within the request body of the PUT request. Weights can be set in any ration, for example, 2:3:5. In a 2:3:5 ratio with three zones, for every 100 requests sent to the cluster, each zone would receive either 20, 30, or 50 search requests in a random order. When assigned a weight of 0, the zone does not receive any search traffic. | N/A |
Example request: Retrieving cluster health for all indexes
다음 요청은 클러스터의 모든 인덱스에 대한 헬스 정보를 가져와요.
REST Python
GET /_cluster/health
Copy Copy as cURL
response = client.cluster.health()
Copy
Example response
응답에는 클러스터 헬스 정보가 들어 있어요.
{
"cluster_name" : "opensearch-cluster",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"discovered_master" : true,
"discovered_cluster_manager" : true,
"active_primary_shards" : 138,
"active_shards" : 138,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 110,
"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" : 55.64516129032258
}
응답이 yellow 상태를 보여주는 이유는 복제 샤드를 할당할 수 없는 단일 노드 클러스터이기 때문이에요. timed_out 필드가 false라는 것은 기본 타임아웃 기간 안에 응답이 반환됐다는 뜻이에요.
Example request: Waiting for a specific health status
다음 요청은 클러스터가 yellow 상태 이상이 될 때까지 50초를 기다려요.
REST Python
GET /_cluster/health?wait_for_status=yellow&timeout=50s
Copy Copy as cURL
response = client.cluster.health(
params = { "wait_for_status": "yellow", "timeout": "50s" }
)
Copy 50초가 지나기 전에 클러스터 헬스가 yellow나 green이 되면 요청은 즉시 응답을 반환해요. 그렇지 않으면 타임아웃을 초과하는 즉시 응답을 반환합니다.
Example request: Retrieving cluster health by awareness attribute
어워니스 속성(예: zone이나 rack)별로 클러스터 헬스를 확인하려면 level 쿼리 파라미터에 awareness_attributes를 지정하세요.
REST Python
GET /_cluster/health?level=awareness_attributes
Copy Copy as cURL
response = client.cluster.health(
params = { "level": "awareness_attributes" }
)
Copy 응답에는 어워니스 속성별로 구분된 클러스터 헬스 지표가 들어 있어요.
{
"cluster_name": "runTask",
"status": "green",
"timed_out": false,
"number_of_nodes": 3,
"number_of_data_nodes": 3,
"discovered_master": true,
"discovered_cluster_manager": true,
"active_primary_shards": 0,
"active_shards": 0,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 0,
"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": 100,
"awareness_attributes": {
"zone": {
"zone-3": {
"active_shards": 0,
"initializing_shards": 0,
"relocating_shards": 0,
"unassigned_shards": 0,
"data_nodes": 1,
"weight": 1
},
"zone-1": {
"active_shards": 0,
"initializing_shards": 0,
"relocating_shards": 0,
"unassigned_shards": 0,
"data_nodes": 1,
"weight": 1
},
"zone-2": {
"active_shards": 0,
"initializing_shards": 0,
"relocating_shards": 0,
"unassigned_shards": 0,
"data_nodes": 1,
"weight": 1
}
},
"rack": {
"rack-3": {
"active_shards": 0,
"initializing_shards": 0,
"relocating_shards": 0,
"unassigned_shards": 0,
"data_nodes": 1,
"weight": 1
},
"rack-1": {
"active_shards": 0,
"initializing_shards": 0,
"relocating_shards": 0,
"unassigned_shards": 0,
"data_nodes": 1,
"weight": 1
},
"rack-2": {
"active_shards": 0,
"initializing_shards": 0,
"relocating_shards": 0,
"unassigned_shards": 0,
"data_nodes": 1,
"weight": 1
}
}
}
}
특정 어워니스 속성에 관심이 있다면 어워니스 속성 이름을 쿼리 파라미터로 포함하면 돼요.
REST Python
GET /_cluster/health?level=awareness_attributes&awareness_attribute=zone
Copy Copy as cURL
response = client.cluster.health(
params = { "level": "awareness_attributes", "awareness_attribute": "zone" }
)
Copy 위 요청에 대한 응답으로 OpenSearch는 zone 어워니스 속성에 대한 클러스터 헬스 정보만 반환해요.
할당되지 않은 샤드 정보는 replica count enforcement를 활성화하고 어워니스 속성에 대해 forced awareness를 클러스터 시작 전에(또는 클러스터 시작 후 인덱싱 요청이 오기 전에) 구성했을 때만 정확해요. 클러스터가 인덱싱 요청을 받은 후에 복제 강제를 활성화하면 할당되지 않은 샤드 정보가 부정확할 수 있어요. replica count enforcement와 forced awareness를 모두 구성하지 않으면 unassigned_shards 필드에는 -1이 들어갑니다.
Response body fields
다음 표는 모든 응답 필드를 보여줘요.
| Field | Data type | Description | | cluster_name | String | The name of the cluster. | | status | String | The overall cluster health status based on the state of shard allocation. - green: All primary and replica shards are allocated. - yellow: All primary shards are allocated, but some replicas are not. - red: At least one primary shard is unassigned. The overall status is determined by the worst shard status across all indexes. | | timed_out | Boolean | Indicates whether the request exceeded the timeout period before the desired health status was reached. false means the response was returned within the timeout period. true means the timeout expired before the desired status was achieved. | | number_of_nodes | Integer | The total number of nodes in the cluster, including all node types (data, cluster manager, ingest, and so on). | | number_of_data_nodes | Integer | The number of nodes designated as data nodes in the cluster. Data nodes store shards and handle data-related operations. | | discovered_cluster_manager | Boolean | Indicates whether the cluster manager node has been discovered and is reachable. If false, the cluster may be in an unstable state. | | discovered_master | Boolean | Legacy field. Use discovered_cluster_manager instead. Retained for backward compatibility. | | active_primary_shards | Integer | The number of primary shards that are currently allocated and active in the cluster. Each document is stored in exactly one primary shard. | | active_shards | Integer | The total number of active shards, including both primary and replica shards. A higher number indicates better data redundancy. | | relocating_shards | Integer | The number of shards currently being moved from one node to another. Shard relocation occurs during rebalancing or when nodes join or leave the cluster. | | initializing_shards | Integer | The number of shards currently being initialized. This occurs when an index is first created or when a node rejoins the cluster and needs to recover shard data. | | unassigned_shards | Integer | The number of shards that exist in the cluster state but are not allocated to any node. Unassigned shards typically occur when replicas cannot be allocated (in a single-node cluster) or when a node fails and shards need to be reallocated. | | delayed_unassigned_shards | Integer | The number of unassigned shards whose allocation has been intentionally delayed. OpenSearch can delay allocation to avoid unnecessary shard movements when a node briefly disconnects and is expected to return. | | number_of_pending_tasks | Integer | The number of cluster-level changes (such as index creation, mapping updates, or shard allocation decisions) that are queued and awaiting execution by the cluster manager. | | number_of_in_flight_fetch | Integer | The number of ongoing shard-level fetch operations currently being executed across the cluster. | | task_max_waiting_in_queue_millis | Integer | The time in milliseconds that the longest-waiting task has been in the queue. High values may indicate that the cluster manager is overloaded. | | active_shards_percent_as_number | Double | The percentage of shards that are active out of the total number of shards (primary and replicas) that should exist. A value of 100.0 indicates all shards are allocated. | | indices | Object | Returned when level=indices or level=shards. Contains per-index health information with the same structure as the cluster-level fields. | | shards | Object | Returned when level=shards. Contains per-shard health information, nested within the indices object. | | awareness_attributes | Object | Returned when level=awareness_attributes. Contains cluster health information partitioned by awareness attributes (such as zone or rack). |
Required permissions
Security 플러그인을 사용한다면 적절한 권한(cluster:monitor/health)을 가지고 있는지 확인하세요.