Elasticsearch集羣監控狀態指標分三個級別
●集羣級別:集羣級別的監控主要是針對整個Elasticsearch集羣來說,包括集羣的健康狀況、集羣的狀態等。
●節點級別:節點級別的監控主要是針對每個Elasticsearch實例的監控,其中包括每個實例的查詢索引指標和物理資源使用指標。
●索引級別:索引級別的監控主要是針對每個索引來說,主要包括每個索引的性能指標。
一、集羣級別
1. 查看集羣健康狀態 (GET _cluster/health)
[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分配給節點。
2查看集羣狀態信息 (GET _cluster/stats?pretty) #集羣狀態信息 ,整個集羣的一些統計信息,例如文檔數、分片數、資源使用情況等信息,從這個接口基本能夠獲取到集羣所有關鍵指標項.
[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:文件系統剩餘總容量。
二、節點級別
節點監控, 即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:老年代垃圾回收總耗時。
三、索引級別
可以查看所有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請求總耗時。
k8s上elasticsearch_exporter部署
1.創建secret文件
apiVersion: v1
kind: Secret
metadata:
name: es-secret-app
namespace: logs
type: Opaque
stringData:
esURI: http://elastic:vRIfHvcdhNZJDGJ0@elasticsearch-master:9200
2.Deployment資源
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: es-exporter
name: es-exporter
namespace: logs
spec:
replicas: 1
selector:
matchLabels:
k8s-app: es-exporter
template:
metadata:
labels:
k8s-app: es-exporter
spec:
containers:
- env:
- name: ES_URI
valueFrom:
secretKeyRef:
name: es-secret-app
key: esURI
- name: ES_ALL
value: "true"
image: bitnami/elasticsearch-exporter:latest
imagePullPolicy: IfNotPresent
name: es-exporter
ports:
- containerPort: 9114
name: metric-port
securityContext:
privileged: false
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
3.service資源
apiVersion: v1
kind: Service
metadata:
name: es-exporter
namespace: logs
labels:
k8s-app: es-exporter
spec:
selector:
k8s-app: es-exporter
ports:
- protocol: TCP
port: 9114
targetPort: 9114
name: metric-port
4.通過k8s的自動發現機制添加ServiceMonitor
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
prometheus: kube-prometheus
release: prometheus
name: es-exporter
namespace: monitoring
spec:
endpoints:
- interval: 30s
port: metric-port
scrapeTimeout: 10s
namespaceSelector:
matchNames:
- logs
selector:
matchLabels:
k8s-app: es-exporter
監控指標說明
- 監控指標解析
####################### 搜索和索引性能 ##########################
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: es_alert
rules:
- alert: es_red_status_alert
expr: elasticsearch_cluster_health_status{color="red"} > 0
for: 3m
labels:
severity: 1
annotations:
summary: "{{ $labels.cluster }} 集羣爲不健康狀態RED!"
- alert: es_yellow_status_alert
expr: elasticsearch_cluster_health_status{color="yellow"} > 0
for: 5m
labels:
severity: 2
annotations:
summary: "{{ $labels.cluster }} 集羣爲不健康狀態YELLOW!"
- alert: ElasticsearchPendingTasks
expr: elasticsearch_cluster_health_number_of_pending_tasks > 0
for: 15m
labels:
severity: warning
annotations:
summary: Elasticsearch pending tasks (instance {{ $labels.instance }})
description: "Elasticsearch has pending tasks. Cluster works slowly.\n VALUE = {{ $value }}\n LABELS = {{ $labels }}"
- alert: ElasticsearchInitializingShardsTooLong
expr: elasticsearch_cluster_health_initializing_shards > 0
for: 15m
labels:
severity: warning
annotations:
summary: Elasticsearch initializing shards too long (instance {{ $labels.instance }})
description: "Elasticsearch has been initializing shards for 15 min\n VALUE = {{ $value }}\n LABELS = {{ $labels }}"
- alert: ElasticsearchHealthyDataNodes
expr: elasticsearch_cluster_health_number_of_data_nodes < 3
for: 0m
labels:
severity: critical
annotations:
summary: Elasticsearch Healthy Data Nodes (instance {{ $labels.instance }})
description: "Missing data node in Elasticsearch cluster\n VALUE = {{ $value }}\n LABELS = {{ $labels }}"
- alert: ElasticsearchHeapUsageWarning
expr: (elasticsearch_jvm_memory_used_bytes{area="heap"} / elasticsearch_jvm_memory_max_bytes{area="heap"}) * 100 > 80
for: 2m
labels:
severity: warning
annotations:
summary: Elasticsearch Heap Usage warning (instance {{ $labels.instance }})
description: "The heap usage is over 80%\n VALUE = {{ $value }}\n LABELS = {{ $labels }}"