当前位置:
首页
文章
前端
详情

Elasticsearch索引监控之Indices Segments API与Indices Shard Stores

本文将继续介绍elasticsearch索引监控之Indices segments与Indices Shard stores api。

Indices Segments

提供Lucene索引(分片级别)使用的segments(段信息)。

其对应的示例代码如下:

 1public static final void test_Indices_segments() { 2        TransportClient client = EsClient.getTransportClient(); 3        try { 4            IndicesSegmentsRequest request = new IndicesSegmentsRequest(); 5            request.indices("logs_write"); 6            ActionFuture<IndicesSegmentResponse> responseFuture = client.admin().indices().segments(request); 7            IndicesSegmentResponse response = responseFuture.get(); 8            System.out.println(response); 9        } catch (Throwable e) {10            e.printStackTrace();11        } finally {12            EsClient.close(client);13        }14}

返回结果类似:

 1{ 2  "_shards": ... 3  "indices": { 4    "test": { 5      "shards": { 6        "0": [ 7          { 8            "routing": { 9              "state": "STARTED",10              "primary": true,11              "node": "zDC_RorJQCao9xf9pg3Fvw"12            },13            "num_committed_segments": 0,14            "num_search_segments": 1,15            "segments": {16              "_0": {17                "generation": 0,18                "num_docs": 1,19                "deleted_docs": 0,20                "size_in_bytes": 3800,21                "memory_in_bytes": 1410,22                "committed": false,23                "search": true,24                "version": "7.0.0",25                "compound": true,26                "attributes": {27                }28              }29            }30          }31        ]32      }33    }34  }35}

返回结果字段说明如下:

  • _0
    段的名称,表示第一个段。

  • generation
    在需要编写新段时基本上递增的生成数。段名是从这个生成号派生出来的。

  • num_docs
    存储在此段中的未删除文档的数量。

  • deleted_docs
    存储在此段中的已删除文档的数量。如果这个数大于0,那么当这个段合并时,空间就会被回收。

  • size_in_bytes
    段使用的磁盘空间量,以字节为单位。

  • memory_in_bytes
    段存储在内存中的字节数,如果-1表示elasticsearch无法计算。

  • committed
      段是否已在磁盘上同步(是否已经提交到磁盘)。

  • search
    是否可搜索,如果为false,表示段已提交到磁盘,但还没有被refresh,故暂时不可用来搜索。

  • version
    底层使用的lucene版本。

  • compound
    段是否存储在复合文件中。当为true时,这意味着Lucene将该段中的所有文件合并为一个文件,以便保存文件描述符。

  • attributes
    其他属性。

另外Indices Segments支持verbose默认,将输出一些调试信息,其返回结果如下:

 1{ 2        "_0": { 3 4            "ram_tree": [ 5                { 6                    "description": "postings [PerFieldPostings(format=1)]", 7                    "size_in_bytes": 2696, 8                    "children": [ 9                        {10                            "description": "format 'Lucene50_0' ...",11                            "size_in_bytes": 2608,12                            "children" :[ ... ]13                        },14                    ]15                },16                ]17        }18}

Indices Shard Stores

主要展示索引分片副本的存储信息。默认情况下,列表只存储至少有一个未分配副本的分片的信息。当集群健康状态为黄色时,将列出至少有一个未分配副本的分片的存储信息。当集群健康状态为红色时,这将列出具有未分配初选的碎片的存储信息。

对应的JAVA示例如下:

 1public static final void test_Indices_Shard_Stores() { 2   TransportClient client = EsClient.getTransportClient(); 3   try { 4      IndicesShardStoresRequest request = new IndicesShardStoresRequest(); 5      request.indices("logs_write"); 6      ActionFuture<IndicesShardStoresResponse> responseFuture = client.admin().indices().shardStores(request); 7      IndicesShardStoresResponse response = responseFuture.get(); 8      ImmutableOpenMap<String, ImmutableOpenIntMap<List<IndicesShardStoresResponse.StoreStatus>>> data =  response.getStoreStatuses(); 9      List indexList = new ArrayList();10      for (Iterator it = data.keysIt(); it.hasNext(); ) {11         String key = (String)it.next();12         Map indexData = new HashMap();13         indexList.add(indexData);14         List indexShardList = new ArrayList();15         indexData.put(key, indexShardList);16         ImmutableOpenIntMap<List<IndicesShardStoresResponse.StoreStatus>> value = data.get(key);17         for(Iterator it2 = value.keysIt(); it2.hasNext(); ) {18            Integer key2 = (Integer)it2.next();19            Map shardData = new HashMap();20            indexShardList.add(shardData);21            List shardStoreStatusList = new ArrayList();22            shardData.put(key2 + "", shardStoreStatusList);23            List<IndicesShardStoresResponse.StoreStatus> storeStatusList = value.get(key2);24            for(IndicesShardStoresResponse.StoreStatus storeStatus : storeStatusList) {25               Map storeStatusMap = new HashMap();26               shardStoreStatusList.add(storeStatusMap);27               storeStatusMap.put("allocationId", storeStatus.getAllocationId());28               storeStatusMap.put("allocationStatus", storeStatus.getAllocationStatus().value());29               Map discoveryNodeData = new HashMap();30               storeStatusMap.put("discoveryNode", discoveryNodeData);31               DiscoveryNode node = storeStatus.getNode();32               discoveryNodeData.put("name", node.getName());33               discoveryNodeData.put("name", node.getAddress());34               discoveryNodeData.put("attributes", node.getAttributes());35               discoveryNodeData.put("ephemeralId", node.getEphemeralId());36               discoveryNodeData.put("hostAddress", node.getHostAddress());37               discoveryNodeData.put("hostName", node.getHostName());38               discoveryNodeData.put("id", node.getId());39               discoveryNodeData.put("roles", node.getRoles());40            }41         }42      }43      System.out.println(FastJsonUtils.getBeanToJson(indexList));44   } catch (Throwable e) {45      e.printStackTrace();46   } finally {47      EsClient.close(client);48   }49}

返回的结果为:

 1[ 2    { 3        "logs-000002":[ 4        { 5            0:[    // @1 6                    { 7                        "discoveryNode":{   // @2 8                            "hostName":"127.0.0.1", 9                            "roles":[10                                "MASTER",11                                "DATA",12                                "INGEST"13                            ],14                            "name":{15                                "address":"127.0.0.1",16                                "fragment":true,17                                "port":930018                            },19                            "attributes":{20                                "ml.machine_memory":"16964890624",21                                "ml.max_open_jobs":"20",22                                "xpack.installed":"true",23                                "ml.enabled":"true"24                            },25                            "hostAddress":"127.0.0.1",26                            "id":"ekEDWaVVRH-944BgEsfRLA",27                            "ephemeralId":"ox0CP9hhQOu1klZgNv7Ezw"28                        },29                        "allocationId":"KRw3BYPFTrK39HOYXzwXBA",      // @330                        "allocationStatus":"primary"                                      // @431                    }32                ]33            }3435            //由于当前试验环境为单机模式,故省略其他分片信息3637        ]38    }39]

代码@1:分片编号。
代码@2:分片所在的节点的信息,包含名称、角色、id、地址等信息。
代码@3:副本的分配ID。
代码@4:分配的状态,其值为primary、replica、unused。

索引监控相关API就介绍到这里了。

更多文章请关注微信公众号:

Elasticsearch索引监控之Indices Segments API与Indices Shard Stores

一波广告来袭,作者新书《RocketMQ技术内幕》已出版上市:

Elasticsearch索引监控之Indices Segments API与Indices Shard Stores

《RocketMQ技术内幕》已出版上市,目前可在主流购物平台(京东、天猫等)购买,本书从源码角度深度分析了RocketMQ NameServer、消息发送、消息存储、消息消费、消息过滤、主从同步HA、事务消息;在实战篇重点介绍了RocketMQ运维管理界面与当前支持的39个运维命令;并在附录部分罗列了RocketMQ几乎所有的配置参数。本书得到了RocketMQ创始人、阿里巴巴Messaging开源技术负责人、Linux OpenMessaging 主席的高度认可并作序推荐。目前是国内第一本成体系剖析RocketMQ的书籍。

本文分享自微信公众号 - 中间件兴趣圈(dingwpmz_zjj)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

免责申明:本站发布的内容(图片、视频和文字)以转载和分享为主,文章观点不代表本站立场,如涉及侵权请联系站长邮箱:xbc-online@qq.com进行反馈,一经查实,将立刻删除涉嫌侵权内容。