本文將詳細介紹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的書籍。