Elasticsearch Index Monitoring(索引監控)之Index Stats A

本文將詳細介紹Elasticsearch Index Monitoring監控命令之Index Stats API。api

索引狀態統計。默認狀況下,該API會返回全部類型的統計信息,Indices Stats返回以下類型的統計信息。緩存

docs

文檔總數量(包含已刪除的文檔),調用文檔刪除API後並不會當即將文檔物理刪除,會保留一段時間,受refreshing the index的影響。其返回示例以下:微信

1"docs" : {
2         "count" : 1286,
3          "deleted" : 0
4  }

store

索引存儲的總大小,其返回示例以下:運維

1"store" : {
2       "size_in_bytes" : 459254 
3}

其返回字段說明以下:elasticsearch

size_in_bytes
索引大小,單位爲字節。ide

indexing

新增、更新、刪除索引操做的統計信息,其返回示例以下: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        }

其返回字段說明以下:性能

  • index_total
    索引操做總次數。
  • index_time_in_millis
    索引操做總耗時。
  • index_current
    當前正在執行索引操做的個數。
  • index_failed
    失敗的索引操做次數。
  • delete_total
    執行刪除索引操做的次數。
  • delete_time_in_millis
    刪除索引操做總耗時。
  • delete_current
    當前正在執行刪除索引操做的個數。
  • noop_update_total
    空更新總次數(檢測到空更新的次數)。
  • is_throttled
    索引是否處在merge throttling control(合併節流控制狀態)。
  • throttle_time_in_millis
    索引處在merge throttling control(合併節流狀態)的時間開銷。

get

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}

其返回字段說明以下:優化

  • total
    get api總調用次數。
  • time_in_millis
    get api總耗時。
  • exists_total
    命中的次數。
  • exists_time_in_millis
    命中的操做總耗時。
  • missing_total
    未命中的總次數。
  • missing_time_in_millis
    未命中的操做的總耗時。
  • current
    當前正在執行的個數。

search

查詢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        },

其返回字段說明以下:

  • open_contexts
    正在打開的查詢上下文個數。
  • query_total
    查詢出來的總數據條數。
  • query_time_in_millis
    查詢階段所耗費的時間。
  • query_current
    當前正在查詢個數。
  • fetch_total
    Fetch操做的次數。
  • fetch_time_in_millis
    Fetch階段總耗時時間。
  • fetch_current
    正在fetch的次數。
  • scroll_total
    經過scroll api查詢數據總條數。
  • scroll_time_in_millis
    經過scroll api總耗時時間。
  • scroll_current
    當前滾動API調用次數。
  • suggest_total
    經過suggest api獲取的推薦總數量。
  • suggest_time_in_millis
    suggest總耗費時間。
  • suggest_current
    正在執行suggest api的個數。

merges

合併相關的統計信息,其輸出示例以下:

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      }

其返回字段說明以下:

  • current
    總髮生的合併次數。
  • current_docs
    當前正在發生合併的文檔數。
  • current_size_in_bytes
    當前合併參與的文檔總大小,單位字節。
  • total
    總髮生的合併次數。
  • total_time_in_millis
    合併的總耗時(單位毫秒)。
  • total_docs
    merge(合併)時總處理的文檔個數。
  • total_size_in_bytes
    merge(合併)時總處理的文檔總大小(字節)。
  • total_stopped_time_in_millis
    merge(合併)時總中止時間(吞吐率爲0)。
  • total_throttled_time_in_millis
    超過指定吞吐率而暫停的時間(節流)。
  • total_auto_throttle_in_bytes
    自動進行流控的闊值,默認速率20m/s。

refresh

刷新索引相關的統計。

1       "refresh" : {
2        "total" : 15,                                                               
3        "total_time_in_millis" : 0,                                         
4        "listeners" : 0                                                          
5      }

其返回字段說明以下:

  • total
    執行刷新的總次數。
  • total_time_in_millis
    執行刷新總耗時。
  • listeners
    等待刷新偵聽器的數量。

flush

刷盤的統計信息。

1"flush" : {
2        "total" : 5,                                                        
3        "periodic" : 0,                                                  
4        "total_time_in_millis" : 0                                 
5      }

其返回字段說明以下:

  • total
    執行刷盤操做的次數。
  • periodic
    當translog超過刷新閾值時週期性觸發的刷新次數。
  • total_time_in_millis
    刷盤操做總耗時時間。

warmer

索引分片(shard)預熱統計信息,分片預熱是指爲索引建立一個分片節點時,是否對該索引預熱(爲索引建立一bitSet位圖)。其統計示例以下:

1"warmer" : {
2        "current" : 0,    
3        "total" : 5,        
4        "total_time_in_millis" : 0   
5      }

其返回字段說明以下:

  • current
    當前正在預熱的個數。
  • total
    總共發生的預熱次數。
  • total_time_in_millis
    分片預熱總耗時。

query_cache

查詢緩存統計信息,其示例以下:

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      }

其返回字段說明以下:

  • memory_size_in_bytes
    查詢緩存佔用的內存空間,單位爲字節。
  • total_count
    緩存中查詢的總次數,等於hit_count + miss_count。
  • hit_count
    查詢緩存命中的次數。
  • miss_count
    查詢緩存未命中的次數。
  • cache_size
    當前查詢緩存中緩存文檔的個數。
  • cache_count
    查詢緩存總緩存文檔個數(包含已經被換出evictions的文檔個數)。
  • evictions
    查詢緩存被逐出的總數。

fielddata

fielddata統計信息,fielddata主要用加快text字段排序與聚合的性能,存儲詞根與文檔的映射關係存儲在在內存,在內存中進行排序與聚合。

1"fielddata" : {
2          "memory_size_in_bytes" : 0,         
3          "evictions" : 0                                 
4        }

其返回字段說明以下:

  • memory_size_in_bytes
    當前佔用內存的大小。
  • evictions
    被逐出詞根的個數。

completion

completion(自動填充)相關統計,其輸出示例爲:

1"completion" : {
2          "size_in_bytes" : 0                 
3 },

其返回字段說明以下:

  • size_in_bytes
    自動提示佔用字節數。

segments

檢索打開段的內存使用狀況。可選地,設置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   },

其返回字段說明以下:

  • count
    該索引目前擁有的總段數。
  • memory_in_bytes
    該索引緩存在內存中字節數。
  • terms_memory_in_bytes
    倒排索引(term)緩存在內中所佔字節數。
  • stored_fields_memory_in_bytes
    該索引定義爲stored_fields字段在內存中緩存的字節數。
  • term_vectors_memory_in_bytes
    該索引term_vectors(詞向量)在內存中所佔字節數量。
  • norms_memory_in_bytes
    該索引存儲對應norms=true的字段當前在內存中緩存字節數。
  • points_memory_in_bytes
    與地理位置相關的緩存數據。
  • doc_values_memory_in_bytes
    設置爲doc_values緩存在內存中的字節數(doc_values,列式存儲)。
  • index_writer_memory_in_bytes
    用於優化索引寫的緩存(減小寫磁盤的頻率)。
  • version_map_memory_in_bytes
    關於文檔的版本映射所佔內存大小。
  • fixed_bit_set_memory_in_bytes
    fixed_bit_set內存,專門用來作nested查詢的。
  • max_unsafe_auto_id_timestamp
    es內部當前的自增ID。
  • file_sizes
    其中若是設置爲true,則file_sizes主要包含以下統計信息:
    Elasticsearch Index Monitoring(索引監控)之Index Stats A

translog

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        }

其返回字段說明以下:

  • operations
    寫translog的次數(索引文檔、更新文檔、刪除文檔的總操做數量)。
  • size_in_bytes
    translog實例管理的translog文件總大小。(一個索引引擎(InternalEngine)示例包含一個Translog實例)。
  • uncommitted_operations
    當前還未提交到lucene中的操做次數(索引文檔、更新文檔、刪除文檔的操做數量)。
  • uncommitted_size_in_bytes
    translog中未提交到Lucene中的字節數。
  • earliest_last_modified_age
    以秒爲單位返回translog文件中最老條目的年齡。

request_cache

請求緩存的統計信息,其輸出示例以下:

1"request_cache" : {
2          "memory_size_in_bytes" : 0,                         
3          "evictions" : 0,                                               
4          "hit_count" : 0,                                               
5          "miss_count" : 0                                            
6},

其返回字段說明以下:

  • memory_size_in_bytes
    請求緩存佔用內存總大小。
  • evictions
    請求緩存被剔除出次數。
  • hit_count
    請求緩存被命中次數。
  • miss_count
    請求緩存未命中次數。

recovery

recovery(恢復)相關的統計信息,其輸出示例:

1"recovery" : {
2          "current_as_source" : 0,                                                  
3          "current_as_target" : 0,                                
4          "throttle_time_in_millis" : 0                          
5}

其返回字段說明以下:

  • current_as_source
    做爲源分片,正在執行恢復的分片數量 。
  • current_as_target
    做爲目標分片,正在執行恢復的分片數量。
  • throttle_time_in_millis
    恢復過程總等待時間。

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。

更多文章請關注微信公衆號:

Elasticsearch Index Monitoring(索引監控)之Index Stats A
一波廣告來襲:本文做者新書《RocketMQ技術內幕》已出版上市。
Elasticsearch Index Monitoring(索引監控)之Index Stats A

《RocketMQ技術內幕》已出版上市,目前可在主流購物平臺(京東、天貓等)購買,本書從源碼角度深度分析了RocketMQ NameServer、消息發送、消息存儲、消息消費、消息過濾、主從同步HA、事務消息;在實戰篇重點介紹了RocketMQ運維管理界面與當前支持的39個運維命令;並在附錄部分羅列了RocketMQ幾乎全部的配置參數。本書獲得了RocketMQ創始人、阿里巴巴Messaging開源技術負責人、Linux OpenMessaging 主席的高度承認並做序推薦。目前是國內第一本成體系剖析RocketMQ的書籍。

相關文章
相關標籤/搜索