本文将详细介绍Elasticsearch Index Monitoring监控命令之Index Stats API。api
索引状态统计。默认状况下,该API会返回全部类型的统计信息,Indices Stats返回以下类型的统计信息。缓存
文档总数量(包含已删除的文档),调用文档删除API后并不会当即将文档物理删除,会保留一段时间,受refreshing the index的影响。其返回示例以下:微信
1"docs" : { 2 "count" : 1286, 3 "deleted" : 0 4 }
索引存储的总大小,其返回示例以下:运维
1"store" : { 2 "size_in_bytes" : 459254 3}
其返回字段说明以下:elasticsearch
size_in_bytes
索引大小,单位为字节。ide
新增、更新、删除索引操做的统计信息,其返回示例以下:oop
1"indexing" : { 2 "index_total" : 0, 3 "index_time_in_millis" : 0, 4 "index_current" : 0, 5 "index_failed" : 0, 6 "delete_total" : 0, 7 "delete_time_in_millis" : 0, 8 "delete_current" : 0, 9 "noop_update_total" : 0, 10 "is_throttled" : false, 11 "throttle_time_in_millis" : 0 12 }
其返回字段说明以下:性能
get api 统计信息,其返回示例以下:fetch
1"get" : { 2 "total" : 0, 3 "time_in_millis" : 0, 4 "exists_total" : 0, 5 "exists_time_in_millis" : 0, 6 "missing_total" : 0, 7 "missing_time_in_millis" : 0, 8 "current" : 0 9}
其返回字段说明以下:优化
查询API的统计信息,其返回示例以下:
1 "search" : { 2 "open_contexts" : 0, 3 "query_total" : 0, 4 "query_time_in_millis" : 0, 5 "query_current" : 0, 6 "fetch_total" : 0, 7 "fetch_time_in_millis" : 0, 8 "fetch_current" : 0, 9 "scroll_total" : 0, 10 "scroll_time_in_millis" : 0, 11 "scroll_current" : 0, 12 "suggest_total" : 0, 13 "suggest_time_in_millis" : 0, 14 "suggest_current" : 0 15 },
其返回字段说明以下:
合并相关的统计信息,其输出示例以下:
1 "merges" : { 2 "current" : 0, 3 "current_docs" : 0, 4 "current_size_in_bytes" : 0, 5 "total" : 0, 6 "total_time_in_millis" : 0, 7 "total_docs" : 0, 8 "total_size_in_bytes" : 0, 9 "total_stopped_time_in_millis" : 0, 10 "total_throttled_time_in_millis" : 0, 11 "total_auto_throttle_in_bytes" : 104857600 12 }
其返回字段说明以下:
刷新索引相关的统计。
1 "refresh" : { 2 "total" : 15, 3 "total_time_in_millis" : 0, 4 "listeners" : 0 5 }
其返回字段说明以下:
刷盘的统计信息。
1"flush" : { 2 "total" : 5, 3 "periodic" : 0, 4 "total_time_in_millis" : 0 5 }
其返回字段说明以下:
索引分片(shard)预热统计信息,分片预热是指为索引建立一个分片节点时,是否对该索引预热(为索引建立一bitSet位图)。其统计示例以下:
1"warmer" : { 2 "current" : 0, 3 "total" : 5, 4 "total_time_in_millis" : 0 5 }
其返回字段说明以下:
查询缓存统计信息,其示例以下:
1"query_cache" : { 2 "memory_size_in_bytes" : 0, 3 "total_count" : 0, 4 "hit_count" : 0, 5 "miss_count" : 0, 6 "cache_size" : 0, 7 "cache_count" : 0, 8 "evictions" : 0 9 }
其返回字段说明以下:
fielddata统计信息,fielddata主要用加快text字段排序与聚合的性能,存储词根与文档的映射关系存储在在内存,在内存中进行排序与聚合。
1"fielddata" : { 2 "memory_size_in_bytes" : 0, 3 "evictions" : 0 4 }
其返回字段说明以下:
completion(自动填充)相关统计,其输出示例为:
1"completion" : { 2 "size_in_bytes" : 0 3 },
其返回字段说明以下:
检索打开段的内存使用状况。可选地,设置include_segment_file_size=true(默认为false),将输出每一个Lucene索引文件的聚合磁盘使用状况,其返回示例以下:
1"segments" : { 2 "count" : 32, 3 "memory_in_bytes" : 38078, 4 "terms_memory_in_bytes" : 23838, 5 "stored_fields_memory_in_bytes" : 9984, 6 "term_vectors_memory_in_bytes" : 0, 7 "norms_memory_in_bytes" : 2048, 8 "points_memory_in_bytes" : 32, 9 "doc_values_memory_in_bytes" : 2176, 10 "index_writer_memory_in_bytes" : 0, 11 "version_map_memory_in_bytes" : 0, 12 "fixed_bit_set_memory_in_bytes" : 0, 13 "max_unsafe_auto_id_timestamp" : -1, 14 "file_sizes" : { } 15 },
其返回字段说明以下:
translog统计信息(有点相似于Innodb的redo日志),其输出示例以下:
1"translog" : { 2 "operations" : 0, 3 "size_in_bytes" : 1100, 4 "uncommitted_operations" : 0, 5 "uncommitted_size_in_bytes" : 1100, 6 "earliest_last_modified_age" : 0 7 }
其返回字段说明以下:
请求缓存的统计信息,其输出示例以下:
1"request_cache" : { 2 "memory_size_in_bytes" : 0, 3 "evictions" : 0, 4 "hit_count" : 0, 5 "miss_count" : 0 6},
其返回字段说明以下:
recovery(恢复)相关的统计信息,其输出示例:
1"recovery" : { 2 "current_as_source" : 0, 3 "current_as_target" : 0, 4 "throttle_time_in_millis" : 0 5}
其返回字段说明以下:
Indices Stats返回的结果是在索引级别的聚合,包含三个维度:primaries(全部主节点进行聚合)、total(全部主节点、副本节点进行聚合)、indices(索引级别)。
下面给出在JAVA中使用Index Stats示例来结束本篇的讲解。
ElasticSearch Index Stats JAVA示例以下:(当前elasticsearch6.4.0 High Rest Client未提供对应API的封装)
1public static final void test_Indices_StatsIndex() { 2 TransportClient client = EsClient.getTransportClient(); 3 try { 4 IndicesStatsRequest request = new IndicesStatsRequest(); 5// request.indices("aggregations_index02"); 6// request.indices("logs_write"); 7// request.includeSegmentFileSizes(true); 8 ActionFuture<IndicesStatsResponse> responseFuture = client.admin().indices().stats(request); 9 IndicesStatsResponse response = responseFuture.get(); 10 System.out.println(response); 11// System.out.println(result); 12 } catch (Throwable e) { 13 e.printStackTrace(); 14 } finally { 15 EsClient.close(client); 16 } 17 }
其返回的结果:
1{ 2 "_shards" : { 3 "total" : 172, 4 "successful" : 86, 5 "failed" : 0 6 }, 7 "_all" : { 8 "primaries" : { 9 "docs" : { 10 "count" : 4166, 11 "deleted" : 0 12 }, 13 "store" : { 14 "size_in_bytes" : 929840 15 }, 16 // ... 省略部分选项 17 }, 18 "total" : { 19 "docs" : { 20 "count" : 4166, 21 "deleted" : 0 22 }, 23 "store" : { 24 "size_in_bytes" : 929840 25 }, 26 // ... 省略部分选项 27 } 28 }, 29 "indices" : { 30 "aggregations_index04" : { 31 "uuid" : "2_6WutahTHa6iK52E7CwZQ", 32 "primaries" : { 33 // ... 省略部分选项 34 }, 35 "total" : { 36 // ... 省略部分选项 37 } 38 }, 39 "alias_demo" : { 40 "uuid" : "EltFD6Y6TA-lpfntx00naw", 41 "primaries" : { 42 43 }, 44 "total" : { 45 46 } 47 48 } // 省略其余索引 49 } 50}
本文详细介绍了Index Stats API的使用,特别在结合源码的基础上给出该API响应结果中各个字段含义的解读,包含docs、store、indexing、get、search、merges、refresh、flush、warmer、query_cache、fielddata、completion、segments、translog、request_cache、recovery。
更多文章请关注微信公众号:
一波广告来袭:本文做者新书《RocketMQ技术内幕》已出版上市。
《RocketMQ技术内幕》已出版上市,目前可在主流购物平台(京东、天猫等)购买,本书从源码角度深度分析了RocketMQ NameServer、消息发送、消息存储、消息消费、消息过滤、主从同步HA、事务消息;在实战篇重点介绍了RocketMQ运维管理界面与当前支持的39个运维命令;并在附录部分罗列了RocketMQ几乎全部的配置参数。本书获得了RocketMQ创始人、阿里巴巴Messaging开源技术负责人、Linux OpenMessaging 主席的高度承认并做序推荐。目前是国内第一本成体系剖析RocketMQ的书籍。