Elasticsearch集群健康

本文详细解读了Elasticsearch 7.13 中的集群健康状态API,包括响应字段如cluster_name、status、数量指标等,并提供了实例和参考链接,帮助理解集群运行状况和潜在问题。

官网文档:

https://www.elastic.co/guide/en/elasticsearch/reference/7.13/cluster-health.html#cluster-health-api-request

命令

curl -XGET 'http://ip:9200/_cluster/health?pretty'

返回举例:

{

  "cluster_name" : "xwliu07-application",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 2,
  "number_of_data_nodes" : 2,
  "active_primary_shards" : 5,
  "active_shards" : 10,
  "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.0
}

官网原文:

Response bodyedit
cluster_name
(string) The name of the cluster.
status
(string) Health status of the cluster, based on the state of its primary and replica shards. Statuses are:

green
All shards are assigned.
yellow
All primary shards are assigned, but one or more replica shards are unassigned. If a node in the cluster fails, some data could be unavailable until that node is repaired.
red
One or more primary shards are unassigned, so some data is unavailable. This can occur briefly during cluster startup as primary shards are assigned.
timed_out
(Boolean) If false the response returned within the period of time that is specified by the timeout parameter (30s by default).
number_of_nodes
(integer) The number of nodes within the cluster.
number_of_data_nodes
(integer) The number of nodes that are dedicated data nodes.
active_primary_shards
(integer) The number of active primary shards.
active_shards
(integer) The total number of active primary and replica shards.
relocating_shards
(integer) The number of shards that are under relocation.
initializing_shards
(integer) The number of shards that are under initialization.
unassigned_shards
(integer) The number of shards that are not allocated.
delayed_unassigned_shards
(integer) The number of shards whose allocation has been delayed by the timeout settings.
number_of_pending_tasks
(integer) The number of cluster-level changes that have not yet been executed.
number_of_in_flight_fetch
(integer) The number of unfinished fetches.
task_max_waiting_in_queue_millis
(integer) The time expressed in milliseconds since the earliest initiated task is waiting for being performed.
active_shards_percent_as_number
(float) The ratio of active shards in the cluster expressed as a percentage.

cluster_name:集群名称

status:集群状态,指示着当前集群在总体上是否工作正常。它的三种颜色含义如下:
green:所有的主分片和副本分片都正常运行。
yellow:所有的主分片都正常运行,但不是所有的副本分片都正常运行,此时集群可以正常服务所有请求,但是在硬件故障时有丢失数据的风险。
red:有主分片没能正常运行。

timed_out:是否超时

number_of_nodes:集群节点数量

number_of_data_nodes:数据节点数量

active_primary_shards:主分片数量

active_shards:所有分片数量包括主副分片

relocating_shards:大于 0 表示 Elasticsearch 正在集群内移动数据的分片 , 来提升负载均衡和故 障转移。这通常发生在添加新节点、重启失效的节点或者删除节点的时候

initializing_shards:正在初始化的分片数量,当用户刚刚创建一个新的索引或者重启一个节点的时候,这个数值会大于 0

unassigned_shards:未分配的副本分片数量,单节点集群中副本是未分配的,因为都在一个节点上

delayed_unassigned_shards:延迟未分配的副本数量

number_of_pending_tasks :代办的任务数量,pending task只能由主节点来进行处理,这些任务包括创建索引并将shards分配给节点,如果该指标数值一直未减小代表集群存在不稳定因素

number_of_in_flight_fetch : 未完成的提取次数 

task_max_waiting_in_queue_millis : 最早启动的任务等待执行到目前的时间,就是最大等待时长(以毫秒为单位)。

active_shards_percent_as_number:集群分片健康度,活跃分片数占总分片数比例,如果为 0 则表示不可用,上述案例是100说明很健康。

参考博客:

https://www.elastic.co/guide/en/elasticsearch/reference/7.13/cluster-health.html#cluster-health-api-request

https://blog.youkuaiyun.com/nandao158/article/details/109024164

https://www.jianshu.com/p/7540ebec4096

https://blog.youkuaiyun.com/u010824591/article/details/78614505

### 如何监控 Elasticsearch 集群健康状态 #### 使用内置 API 进行健康检查 Elasticsearch 提供了多种内置API来帮助管理员了解集群的整体健康状况。通过`_cluster/health`端点,可以获得关于集群健康的概览信息[^1]。 ```bash GET /_cluster/health?pretty=true ``` 此命令返回的数据结构中包含了诸如status字段,它能指示当前集群的状态——绿色表示一切正常;黄色意味着虽然所有数据都可用但是存在未分配的副本分片;红色则表明有主分片未能成功分配,这可能会影响某些索引操作的成功执行。 #### 实施资源级别监控 除了利用官方提供的工具外,还应该关注底层硬件资源的表现情况。对于承载Elasticsearch实例的服务器而言,CPU利用率、内存消耗以及I/O读写速度都是重要的考量因素之一。这些基础层面的信息能够揭示潜在瓶颈所在之处并提前预警可能出现的问题[^5]。 #### 设置自定义告警规则 基于上述提到的各种度量标准设定合理的阈值范围,并据此触发相应的通知机制是非常必要的。当任何一项关键性能指标偏离预期水平时,及时收到警告可以帮助运维人员迅速做出反应,从而减少故障时间窗口内的损失风险。例如,在Kibana界面内创建Watchers对象实现自动化报警流程[^3]。 #### 定期审查日志文件 最后但同样重要的是定期查看由各个节点产生的日志记录。它们不仅记载着日常运作期间发生的各类事件详情,而且往往隐藏着许多有关系统内部行为模式变化的重要线索。借助Logstash或者其他类似的解析引擎处理海量的日志条目,从中挖掘有价值的情报用于改进现有策略或是排查疑难杂症[^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值