學習Elasticsearch有一段時間了,參考網上的一些資料,對於Elasticsearch集羣狀態一些重要監控指標數據在此進行小結,以加深理解。node
Elasticsearch集羣監控狀態指標分三個級別
- 集羣級別:集羣級別的監控主要是針對整個Elasticsearch集羣來講,包括集羣的健康情況、集羣的狀態等。
- 節點級別:節點級別的監控主要是針對每一個Elasticsearch實例的監控,其中包括每一個實例的查詢索引指標和物理資源使用指標。
- 索引級別:索引級別的監控主要是針對每一個索引來講,主要包括每一個索引的性能指標。linux
1、集羣級別 git
1. 查看集羣健康狀態 (GET _cluster/health)github
[root@elk-node01 ~]# curl -X GET 'http://10.0.8.47:9200/_cluster/health?pretty' { "cluster_name" : "kevin-elk", "status" : "green", "timed_out" : false, "number_of_nodes" : 3, "number_of_data_nodes" : 3, "active_primary_shards" : 2234, "active_shards" : 4468, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 0, "delayed_unassigned_shards" : 0, "number_of_pending_tasks" : 0, "number_of_in_flight_fetch" : 0, "task_max_waiting_in_queue_millis" : 0, "active_shards_percent_as_number" : 100.0 }
關鍵指標說明
status:集羣狀態,分爲green、yellow和red。
number_of_nodes/number_of_data_nodes:集羣的節點數和數據節點數。
active_primary_shards:集羣中全部活躍的主分片數。
active_shards:集羣中全部活躍的分片數。
relocating_shards:當前節點遷往其餘節點的分片數量,一般爲0,當有節點加入或者退出時該值會增長。
initializing_shards:正在初始化的分片。
unassigned_shards:未分配的分片數,一般爲0,當有某個節點的副本分片丟失該值就會增長。
number_of_pending_tasks:是指主節點建立索引並分配shards等任務,若是該指標數值一直未減少表明集羣存在不穩定因素
active_shards_percent_as_number:集羣分片健康度,活躍分片數佔總分片數比例。
number_of_pending_tasks:pending task只能由主節點來進行處理,這些任務包括建立索引並將shards分配給節點。web
2. 查看集羣狀態信息 (GET _cluster/stats?pretty)
#集羣狀態信息 ,整個集羣的一些統計信息,例如文檔數、分片數、資源使用狀況等信息,從這個接口基本可以獲取到集羣全部關鍵指標項.json
[root@elk-node01 ~]# curl -X GET 'http://10.0.8.47:9200/_cluster/stats?pretty' ............. 出來的信息不少,這裏省略
關鍵指標說明
indices.count:索引總數。
indices.shards.total:分片總數。
indices.shards.primaries:主分片數量。
docs.count:文檔總數。
store.size_in_bytes:數據總存儲容量。
segments.count:段總數。
nodes.count.total:總節點數。
nodes.count.data:數據節點數。
nodes. process. cpu.percent:節點CPU使用率。
fs.total_in_bytes:文件系統使用總容量。
fs.free_in_bytes:文件系統剩餘總容量。緩存
2、節點級別 bash
節點監控, 即node線程組狀態 (GET _nodes/stats/thread_pool?pretty)網絡
[root@elk-node01 ~]# curl -X GET 'http://10.0.8.47:9200/stats/thread_pool?pretty 輸出信息較多部分省略 ................. ................. "indices": { "docs": { "count": 8111612, # 顯示節點上有多少文檔 "deleted": 16604 # 有多少已刪除的文檔還未從數據段中刪除 }, "store": { "size_in_bytes": 2959876263 # 顯示該節點消耗了多少物理存儲 }, "indexing": { #表示索引文檔的次數,這個是經過一個計數器累加計數的。當文檔被刪除時,它不會減小。注意這個值永遠是遞增的,發生在內部索引數據的時候,包括那些更新操做 "index_total": 17703152, "is_throttled": false, "throttle_time_in_millis": 0 # 這個值高的時候,說明磁盤流量設置過低 }, ................. ................. }, "search": { "open_contexts": 0, # 主動檢索的次數, "query_total": 495447, # 查詢總數 "query_time_in_millis": 298344, # 節點啓動到此查詢消耗總時間, query_time_in_millis / query_total的比值能夠做爲你的查詢效率的粗略指標。比值越大,每一個查詢用的時間越多,你就須要考慮調整或者優化。 "query_current": 0, #後面關於fetch的統計,是描述了查詢的第二個過程(也就是query_the_fetch裏的fetch)。fetch花的時間比query的越多,表示你的磁盤很慢,或者你要fetch的的文檔太多。或者你的查詢參數分頁條件太大,(例如size等於1萬 "fetch_total": 130194, "suggest_current": 0 }, "merges": { # 包含lucene段合併的信息,它會告訴你有多少段合併正在進行,參與的文檔數,這些正在合併的段的總大小,以及花在merge上的總時間。 若是你的集羣寫入比較多,這個merge的統計信息就很重要。merge操做會消耗大量的磁盤io和cpu資源。若是你的索引寫入不少,你會看到大量的merge操做 ................. ................. }, "fielddata": { #顯示了fielddata使用的內存,fielddata用於聚合、排序等。這裏也有一個淘汰數,不像filter_cache,這裏的淘汰數頗有用,它必須是0或者接近0,由於fielddata 不是緩存,任何淘汰的代價都是很大的,必需要避免的。若是你看到了淘汰,你必須從新評估你的內存狀況,關於fielddata的限制,以及查詢,或者三者所有。 ................. ................. }, "segments": { 告訴你當前節點的lucene 段的個數,這多是一個很重要的數字。大多數的索引應該在50到150個段左右,即使是幾T大小的數十億的文檔。大量的段會帶來合併的問題(例如:合併趕不上段的產生)。注意這個統計是對一個節點上全部的索引而言的 其中內存的統計,能夠告訴你Lucene的段自身須要多少內存。這裏包括基礎的數據結構,包括提交列表,詞典,bloom過濾器等。段的數量多會增長承載這些數據結構的開銷,這個內存的使用就是對這個開銷的度量。
關鍵指標說明
indices.docs.count:索引文檔數。
segments.count:段總數。
jvm.heap_used_percent:內存使用百分比。
thread_pool.{bulk, index, get, search}.{active, queue, rejected}:線程池的一些信息,包括bulk、index、get和search線程池,主要指標有active(激活)線程數,線程queue(隊列)數和rejected(拒絕)線程數量。數據結構
如下一些指標是一個累加值,當節點重啓以後會清零
indices.indexing.index_total:索引文檔數。
indices.indexing.index_time_in_millis:索引總耗時。
indices.get.total:get請求數。
indices.get.time_in_millis:get請求總耗時。
indices.search.query_total:search總請求數。
indices.search.query_time_in_millis:search請求總耗時。
indices.search.fetch_total:fetch操做總數量,即提取總數。
indices.search.fetch_time_in_millis:fetch請求總耗時,即花費在提取上的總時間。
jvm.gc.collectors.young.collection_count:年輕代垃圾回收次數。
jvm.gc.collectors.young.collection_time_in_millis:年輕代垃圾回收總耗時。
jvm.gc.collectors.old.collection_count:老年代垃圾回收次數。
jvm.gc.collectors.old.collection_time_in_millis:老年代垃圾回收總耗時。
3、索引級別
能夠查看全部index的相關信息 (GET _stats)
[root@elk-node01 ~]# curl -X GET 'http://10.0.8.47:9200/_stats ............. 輸出信息較多,此處省略
關鍵指標說明
indexname.primaries.docs.count:索引文檔數量。
如下一些指標是一個累加值,當節點重啓以後會清零
indexname.primaries.indexing.index_total:索引文檔數,即索引的總文件數。
indexname.primaries.indexing.index_time_in_millis:索引總耗時,即索引文檔的總時間數。
indexname.primaries.get.total:get請求數。
indexname.primaries.get.time_in_millis:get請求總耗時。
indexname.primaries.search.query_total:search總請求數。
indexname.primaries.search.query_time_in_millis:search請求總耗時。indices.search.fetch_total:fetch操做總數量。
indexname.primaries.search.fetch_time_in_millis:fetch請求總耗時。
indexname.primaries.refresh.total:refresh請求總量。
indexname.primaries.refresh.total_time_in_millis:refresh請求總耗時。
indexname.primaries.flush.total:flush請求總量。
indexname.primaries.flush.total_time_in_millis:flush請求總耗時。
Prometheus+Elasticsearch+Grafana環境裏ES的監控指標
- 簡單安裝elasticsearch
[root@elk-node1 ~]# wget https://github.com/justwatchcom/elasticsearch_exporter/releases/download/v1.0.4rc1/elasticsearch_exporter-1.0.4rc1.linux-amd64.tar.gz [root@elk-node1 ~]# tar zxvf elasticsearch_exporter-1.0.4rc1.linux-amd64.tar.gz [root@elk-node1 ~]# cd elasticsearch_exporter [root@elk-node1 ~]# cp elasticsearch_exporter /usr/local/bin [root@elk-node1 ~]# /usr/local/bin/elasticsearch_exporter --web.listen-address "0.0.0.0:9109" --es.uri http://elastic:changeme@localhost:9201 [root@elk-node1 ~]# curl localhost:9109/metrics
- 配置Prometheus
- job_name: 'elasticsearch' file_sd_configs: - refresh_interval: 1m files: - ./conf.d/es*.json
- 配置consul或etcd自動發現(這裏省略)
- 監控指標解析
####################### 搜索和索引性能 ##########################
elasticsearch_indices_search_query_total
查詢總數(吞吐量)
elasticsearch_indices_search_query_time_seconds
查詢總時間(性能)
elasticsearch_indices_search_fetch_total
提取總數
elasticsearch_indices_search_fetch_time_seconds
花費在提取上的總時間
######################## 索引請求 ##############################
elasticsearch_indices_indexing_index_total
索引的文件總數
elasticsearch_indices_indexing_index_time_seconds_total
索引文檔總時間
elasticsearch_indices_indexing_delete_total
索引的文件刪除總數
elasticsearch_indices_indexing_delete_time_seconds_total
索引的文件刪除總時間
elasticsearch_indices_refresh_total
索引刷新總數
elasticsearch_indices_refresh_time_seconds_total
刷新指數的總時間
elasticsearch_indices_flush_total
索引刷新總數到磁盤
elasticsearch_indices_flush_time_seconds
將索引刷新到磁盤上的總時間 累計flush時間
######################## JVM內存和垃圾回收 ######################
elasticsearch_jvm_gc_collection_seconds_sum
GC run time in seconds垃圾回收時間
elasticsearch_jvm_gc_collection_seconds_count
Count of JVM GC runs垃圾蒐集數
elasticsearch_jvm_memory_committed_bytes
JVM memory currently committed by area最大使用內存限制
elasticsearch_jvm_memory_max_bytes
配置的最大jvm值
elasticsearch_jvm_memory_pool_max_bytes
JVM內存最大池數
elasticsearch_jvm_memory_pool_peak_max_bytes
最大的JVM內存峯值
elasticsearch_jvm_memory_pool_peak_used_bytes
池使用的JVM內存峯值
elasticsearch_jvm_memory_pool_used_bytes
目前使用的JVM內存池
elasticsearch_jvm_memory_used_bytes
JVM memory currently used by area 內存使用量
####################### 集羣健康和節點可用性 ####################
elasticsearch_cluster_health_status
集羣狀態,green( 全部的主分片和副本分片都正常運行)、yellow(全部的主分片都正常運行,但不是全部的副本分片都正常運行)red(有主分片沒能正常運行)值爲1的即爲對應狀態
elasticsearch_cluster_health_number_of_data_nodes
node節點的數量
elasticsearch_cluster_health_number_of_in_flight_fetch
正在進行的碎片信息請求的數量
elasticsearch_cluster_health_number_of_nodes
集羣內全部的節點
elasticsearch_cluster_health_number_of_pending_tasks
還沒有執行的集羣級別更改
elasticsearch_cluster_health_initializing_shards
正在初始化的分片數
elasticsearch_cluster_health_unassigned_shards
未分配分片數
elasticsearch_cluster_health_active_primary_shards
活躍的主分片總數
elasticsearch_cluster_health_active_shards
活躍的分片總數(包括複製分片)
elasticsearch_cluster_health_relocating_shards
當前節點正在遷移到其餘節點的分片數量,一般爲0,集羣中有節點新加入或者退出時該值會增長
########################### 資源飽和度 ###########################
elasticsearch_thread_pool_completed_count
線程池操做完成(bulk、index、search、force_merge)
elasticsearch_thread_pool_active_count
線程池線程活動(bulk、index、search、force_merge)
elasticsearch_thread_pool_largest_count
線程池最大線程數(bulk、index、search、force_merge)
elasticsearch_thread_pool_queue_count
線程池中的排隊線程數(bulk、index、search、force_merge)
elasticsearch_thread_pool_rejected_count
線程池的被拒絕線程數(bulk、index、search、force_merge)
elasticsearch_indices_fielddata_memory_size_bytes
fielddata緩存的大小(字節)
elasticsearch_indices_fielddata_evictions
來自fielddata緩存的驅逐次數
elasticsearch_indices_filter_cache_evictions
來自過濾器緩存的驅逐次數(僅版本2.x)
elasticsearch_indices_filter_cache_memory_size_bytes
過濾器高速緩存的大小(字節)(僅版本2.x)
elasticsearch_cluster_health_number_of_pending_tasks
待處理任務數
elasticsearch_indices_get_time_seconds
elasticsearch_indices_get_missing_total
丟失的文件的GET請求總數
elasticsearch_indices_get_missing_time_seconds
花費在文檔丟失的GET請求上的總時間
elasticsearch_indices_get_exists_time_seconds
elasticsearch_indices_get_exists_total
elasticsearch_indices_get_total
################### 主機級別的系統和網絡指標 ####################
elasticsearch_process_cpu_percent
Percent CPU used by process CPU使用率
elasticsearch_filesystem_data_free_bytes
Free space on block device in bytes 磁盤可用空間
elasticsearch_process_open_files_count
Open file descriptors ES進程打開的文件描述符
elasticsearch_transport_rx_packets_total
Count of packets receivedES節點之間網絡入流量
elasticsearch_transport_tx_packets_total
Count of packets sentES節點之間網絡出流量
- 預警rules
groups: - name: elasticsearchStatsAlert rules: - alert: Elastic_Cluster_Health_RED expr: elasticsearch_cluster_health_status{color="red"}==1 for: 1m labels: severity: critical annotations: summary: "Instance {{ $labels.instance }}: not all primary and replica shards are allocated in elasticsearch cluster {{ $labels.cluster }}" description: "Instance {{ $labels.instance }}: not all primary and replica shards are allocated in elasticsearch cluster {{ $labels.cluster }}." - alert: Elastic_Cluster_Health_Yellow expr: elasticsearch_cluster_health_status{color="yellow"}==1 for: 1m labels: severity: critical annotations: summary: " Instance {{ $labels.instance }}: not all primary and replica shards are allocated in elasticsearch cluster {{ $labels.cluster }}" description: "Instance {{ $labels.instance }}: not all primary and replica shards are allocated in elasticsearch cluster {{ $labels.cluster }}." - alert: Elasticsearch_JVM_Heap_Too_High expr: elasticsearch_jvm_memory_used_bytes{area="heap"} / elasticsearch_jvm_memory_max_bytes{area="heap"} > 0.8 for: 1m labels: severity: critical annotations: summary: "ElasticSearch node {{ $labels.instance }} heap usage is high " description: "The heap in {{ $labels.instance }} is over 80% for 15m." - alert: Elasticsearch_health_up expr: elasticsearch_cluster_health_up !=1 for: 1m labels: severity: critical annotations: summary: " ElasticSearch node: {{ $labels.instance }} last scrape of the ElasticSearch cluster health failed" description: "ElasticSearch node: {{ $labels.instance }} last scrape of the ElasticSearch cluster health failed" - alert: Elasticsearch_Too_Few_Nodes_Running expr: elasticsearch_cluster_health_number_of_nodes < 12 for: 1m labels: severity: critical annotations: summary: "There are only {{$value}} < 12 ElasticSearch nodes running " description: "lasticSearch running on less than 12 nodes(total 14)" - alert: Elasticsearch_Count_of_JVM_GC_Runs expr: rate(elasticsearch_jvm_gc_collection_seconds_count{}[5m])>5 for: 1m labels: severity: critical annotations: summary: "ElasticSearch node {{ $labels.instance }}: Count of JVM GC runs > 5 per sec and has a value of {{ $value }} " description: "ElasticSearch node {{ $labels.instance }}: Count of JVM GC runs > 5 per sec and has a value of {{ $value }}" - alert: Elasticsearch_GC_Run_Time expr: rate(elasticsearch_jvm_gc_collection_seconds_sum[5m])>0.3 for: 1m labels: severity: critical annotations: summary: " ElasticSearch node {{ $labels.instance }}: GC run time in seconds > 0.3 sec and has a value of {{ $value }}" description: "ElasticSearch node {{ $labels.instance }}: GC run time in seconds > 0.3 sec and has a value of {{ $value }}" - alert: Elasticsearch_json_parse_failures expr: elasticsearch_cluster_health_json_parse_failures>0 for: 1m labels: severity: critical annotations: summary: " ElasticSearch node {{ $labels.instance }}: json parse failures > 0 and has a value of {{ $value }}" description: "ElasticSearch node {{ $labels.instance }}: json parse failures > 0 and has a value of {{ $value }}" - alert: Elasticsearch_breakers_tripped expr: rate(elasticsearch_breakers_tripped{}[5m])>0 for: 1m labels: severity: critical annotations: summary: " ElasticSearch node {{ $labels.instance }}: breakers tripped > 0 and has a value of {{ $value }}" description: "ElasticSearch node {{ $labels.instance }}: breakers tripped > 0 and has a value of {{ $value }}" - alert: Elasticsearch_health_timed_out expr: elasticsearch_cluster_health_timed_out>0 for: 1m labels: severity: critical annotations: summary: " ElasticSearch node {{ $labels.instance }}: Number of cluster health checks timed out > 0 and has a value of {{ $value }}" description: "ElasticSearch node {{ $labels.instance }}: Number of cluster health checks timed out > 0 and has a value of {{ $value }}"
- Prometheus 配置
rule_files: - /usr/local/prometheus/rules/es*.rules
- 最後可在Grafana 上經過Prometheus數據源進行監控圖形展現