Prometheus 可以很方便的監(jiān)控 Elasticsearch 的指標(biāo)。
方式一:
通過啟動ES自帶的監(jiān)控模塊暴露指標(biāo)數(shù)據(jù),主要步驟如下:
- 在 Elasticsearch 中啟用監(jiān)控模塊修改 Elasticsearch 的配置文件,加入監(jiān)控相關(guān)配置:
xpack.monitoring.collection.enabled: true # 啟用監(jiān)控收集
http.cors.enabled: true
http.cors.allow-origin: "*" # 設(shè)置跨域訪問
重啟 Elasticsearch 實例后,監(jiān)控相關(guān) API 會自動啟用。
- 配置 Prometheus 監(jiān)控 Elasticsearch
在 Prometheus 的配置文件中添加 Elasticsearch 的 job:
scrape_configs:
- job_name: 'elasticsearch'
metrics_path: "/_prometheus/metrics"
static_configs:
- targets:
- "es-master:9200" # Elasticsearch master 節(jié)點地址
- Prometheus 初始抓取后,可以在控制臺看到 Elasticsearch 的相關(guān)指標(biāo),如:
- es_process_cpu_seconds_total # CPU 時間
- es_jvm_memory_bytes_committed # JVM 內(nèi)存占用
- es_indices_indexing_index_total # 索引次數(shù)
- es_nodes_fs_total_bytes # 節(jié)點磁盤空間占用
- 等等
- 根據(jù)指標(biāo)定義告警規(guī)則
當(dāng)某些關(guān)鍵指標(biāo)超過閾值時,Prometheus 可以發(fā)出告警,如:
groups:
- name: elasticsearch
rules:
- alert: ElasticsearchNodeDown
expr: up{job="elasticsearch", instance="es-master:9200"} == 0
for: 5m
labels:
severity: critical
annotations:
summary: "Elasticsearch master node is down"
Prometheus 通過監(jiān)控 Elasticsearch 的 API 獲取各種監(jiān)控指標(biāo),并根據(jù)閾值規(guī)則發(fā)出告警,這可以實現(xiàn)對 Elasticsearch 集群狀態(tài)的實時監(jiān)控與報警。
方式二:
通過 Elasticsearch Exporter 來暴露Elasticsearch指標(biāo)。
安裝 Elasticsearch Exporter 以獲取 Elasticsearch 集群的 metrics 數(shù)據(jù),步驟如下:
(其它安裝方式:https://github.com/prometheus-community/elasticsearch_exporter)
- 下載 Elasticsearch Exporter
wget https://github.com/prometheus-community/elasticsearch_exporter/releases/download/v1.5.0/elasticsearch_exporter-1.5.0.linux-amd64.tar.gz
- 配置 Elasticsearch Exporter
修改 elasticsearch_exporter.yml 配置文件,例如:
cluster.server: http://localhost:9200 # Elasticsearch host
cluster.timeout: 10s
es.all: true # Export all metrics
es.indices: true # Export index metrics
es.shards: true # Export shard metrics
es.nodes: true # Export node metrics
es.cluster_settings: true # Export cluster settings
- 啟動 Elasticsearch Exporter
直接運行 elasticsearch_exporter二進制文件即可:
-config.file啟動項:添加配置文件
其它啟動項:可執(zhí)行elasticsearch_exporter --help查看。
./elasticsearch_exporter -config.file=elasticsearch_exporter.yml
默認(rèn)會監(jiān)聽 9114 端口,可以配置web.listen-address啟動項修改監(jiān)聽端口。
- Prometheus 配置抓取
在 Prometheus 配置文件中添加如下抓取任務(wù):
scrape_configs:
- job_name: elasticsearch
metrics_path: /probe
static_configs:
- targets: ['es1:9114', 'es2:9114'] # 對應(yīng) exporter 端口
重啟 Prometheus,就可以看到有關(guān) Elasticsearch metrics 的監(jiān)控數(shù)據(jù)了。文章來源:http://www.zghlxwxcb.cn/news/detail-494376.html
exporter 支持兩種工作模式:文章來源地址http://www.zghlxwxcb.cn/news/detail-494376.html
- 服務(wù)發(fā)現(xiàn)模式:通過 _cat/nodes 檢索 Elasticsearch 集群的節(jié)點信息,動態(tài)發(fā)現(xiàn)節(jié)點并抓取指標(biāo)數(shù)據(jù)。要啟用此模式,在配置文件中不要指定 cluster.server 選項。
- 靜態(tài)模式:手動指定要抓取的節(jié)點,需要顯式配置 cluster.server 選項指向 Elasticsearch 集群的 API endpoint。
到了這里,關(guān)于Prometheus監(jiān)控Elasticsearch指標(biāo)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!