前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Elasticsearch索引监控之Indices Segments API与Indices Shard Stores

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

作者头像
丁威
发布2019-06-11 14:52:39
8930
发布2019-06-11 14:52:39
举报
文章被收录于专栏:中间件兴趣圈中间件兴趣圈

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

Indices Segments

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

其对应的示例代码如下:

代码语言:javascript
复制
 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}

返回结果类似:

代码语言:javascript
复制
 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默认,将输出一些调试信息,其返回结果如下:

代码语言:javascript
复制
 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示例如下:

代码语言:javascript
复制
 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}

返回的结果为:

代码语言:javascript
复制
 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":9300
18                            },
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",      // @3
30                        "allocationStatus":"primary"                                      // @4
31                    }
32                ]
33            }
34
35            //由于当前试验环境为单机模式,故省略其他分片信息
36
37        ]
38    }
39]

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

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

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-05-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 中间件兴趣圈 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Indices Segments
  • Indices Shard Stores
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档