• ElasticSearch--查看健康状态(health)的方法(API)


    原文网址:ElasticSearch--查看健康状态(health)的方法(API)_IT利刃出鞘的博客-CSDN博客

    简介

    说明

            本文介绍ElasticSearch查看健康状态的方法(API)。

    官网

    https://www.elastic.co/guide/en/elasticsearch/reference/7.1/cluster-health.html

    Head插件查看状态

    Head插件可以查看ES的状态,例如:

    Head插件可以直观看到颜色,但有如下两个缺点:

    1. 生产环境中ES不会放开外网端口,无法用Head插件查看状态。
    2. Head插件只能看到颜色,不能看到详细错误原因

    所以,如果想要查看生产环境的ES状态或者查看详细错误原因,就要用到下边的API。

    API大全

    _cat/health

     API

    作用

    GET _cat/health显示集群的健康信息

    _cat/shards

     API

    作用

    GET _cat/shards查看节点包含的分片信息,包括一个分片是主分片还是一个副本分片、文档的数量、硬盘上占用的字节数、节点所在的位置等信息。

    _cluster/health

     API

    作用

    GET _cluster/health

    集群的状态(检查节点数量)

    GET _cluster/health?level=indices

    所有索引的健康状态(查看有问题的索引)

    GET _cluster/health/my_index

    单个索引的健康状态(查看具体的索引)

    GET _cluster/health?level=shards

    分片级的索引

    _cluster/allocation/explain

     API

    作用

    GET _cluster/allocation/explain

    返回第一个未分配 Shard 的原因

    GET /_cluster/allocation/explain
    {
      "index": "myindex",
      "shard": 0,
      "primary": true
    }

    查看特定分片未分配的原因。

    index:索引名称。
    shard:分片序号。从 0 开始计数。
    primary:是否主分片;true 代表是;false 代表否。

    示例1:索引的健康状态

    方法

    http://IP:9200/_cat/health

     正常的结果

    1635328870 10:01:10 kubernetes-logging green 15 10 2160 1080 2 0 0 0 - 100.0%

    有问题的结果

    1635313779 05:49:39 kubernetes-logging red 15 10 2128 1064 0 0 32 0 - 98.5%

    示例2:分片的状态 

    方法

    http://IP:9200/_cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state
    • v=true, 代表显示字段含义;否则首行内容不显示。
    • h=*,代表列名;
    • s=state,代表基于state方式排序。等价于:s=state:asc,默认升序方式排序。
    • prirep,代表分片类型。p:代表主分片;r:代表副本分片。

    结果

    order_info、test_data等索引包含未分配的副本分片。其集群健康状态肯定是“黄色”。 

    示例3:集群的健康状态

    方法

    http://IP:9200/_cluster/health

    结果

    1. {
    2. "cluster_name": "kubernetes-logging",
    3. "status": "red",
    4. "timed_out": false,
    5. "number_of_nodes": 15,
    6. "number_of_data_nodes": 10,
    7. "active_primary_shards": 1064,
    8. "active_shards": 2128,
    9. "relocating_shards": 0,
    10. "initializing_shards": 0,
    11. "unassigned_shards": 32,
    12. "delayed_unassigned_shards": 0,
    13. "number_of_pending_tasks": 0,
    14. "number_of_in_flight_fetch": 0,
    15. "task_max_waiting_in_queue_millis": 0,
    16. "active_shards_percent_as_number": 98.51851851851852
    17. }

    "unassigned_shards" :未分配的分片数

    示例4:所有索引的健康状态

    方法

    http://IP:9200/_cluster/health?level=indices

    结果

    1. {
    2. // 其他数据
    3. "bj-task-hdfs-rpc-2021.11.24" : {
    4. "status" : "red", // 分片状态为红色
    5. "number_of_shards" : 5, // 主分片数
    6. "number_of_replicas" : 1, // 每个分片的副本数
    7. "active_primary_shards" : 4, // 活动的主分片数,说明 1 个故障
    8. "active_shards" : 7, // 活动的总分片数,说明 3 个故障
    9. "relocating_shards" : 0,
    10. "initializing_shards" : 0,
    11. "unassigned_shards" : 3 // 未分配的分片有3个(1主分片 + 2副本分片)
    12. }
    13. }

    示例5:单个索引的健康状态

    方法

    http://IP:9200/_cluster/health/dev-tool-deployment-service

    结果

    1. {
    2. "cluster_name": "kubernetes-logging",
    3. "status": "red",
    4. "timed_out": false,
    5. "number_of_nodes": 15,
    6. "number_of_data_nodes": 10,
    7. "active_primary_shards": 2,
    8. "active_shards": 4,
    9. "relocating_shards": 0,
    10. "initializing_shards": 0,
    11. "unassigned_shards": 6,
    12. "delayed_unassigned_shards": 0,
    13. "number_of_pending_tasks": 0,
    14. "number_of_in_flight_fetch": 0,
    15. "task_max_waiting_in_queue_millis": 0,
    16. "active_shards_percent_as_number": 98.52534562211981
    17. }

    示例6:查看故障原因

    GET /_cluster/allocation/explain

    结果

    1. {
    2. "index" : "idx",
    3. "shard" : 0,
    4. "primary" : true,
    5. "current_state" : "unassigned",
    6. "unassigned_info" : {
    7. "reason" : "INDEX_CREATED",
    8. "at" : "2017-01-04T18:08:16.600Z",
    9. "last_allocation_status" : "no"
    10. },
    11. "can_allocate" : "no",
    12. "allocate_explanation" : "cannot allocate because allocation is not permitted to any of the nodes",
    13. "node_allocation_decisions" : [
    14. {
    15. "node_id" : "8qt2rY-pT6KNZB3-hGfLnw",
    16. "node_name" : "node-0",
    17. "transport_address" : "127.0.0.1:9401",
    18. "node_attributes" : {},
    19. "node_decision" : "no",
    20. "weight_ranking" : 1,
    21. "deciders" : [
    22. {
    23. "decider" : "filter",
    24. "decision" : "NO",
    25. "explanation" : "node does not match index setting [index.routing.allocation.include] filters [_name:\"non_existent_node\"]"
    26. }
    27. ]
    28. }
    29. ]
    30. }

  • 相关阅读:
    创纪录的1亿RPS DDoS攻击利用HTTP/2快速重置漏洞
    【论文阅读】-- DeepVisualInsight: 深度分类训练时空因果关系的时间旅行可视化
    第13章 并发编程高阶(二)
    小程序源码:恋爱小助手-多玩法安装简单
    使用软路由(openWrt)安装openVPN搭建局域网连接
    【JavaSE】类和对象 【封装、static、代码块、对象的打印】(三)
    阶段二-Day18-Java新特性
    [SWPU2019]Web1
    jvm调优-cpu飙升及响应慢
    特征缩放和转换以及自定义Transformers(Machine Learning 研习之九)
  • 原文地址:https://blog.csdn.net/feiying0canglang/article/details/125813707