Prometheus 可以很方便的监控 Elasticsearch 的指标。
通过启动ES自带的监控模块暴露指标数据,主要步骤如下:
xpack.monitoring.collection.enabled: true # 启用监控收集
http.cors.enabled: true
http.cors.allow-origin: "*" # 设置跨域访问
重启 Elasticsearch 实例后,监控相关 API 会自动启用。
scrape_configs:
- job_name: 'elasticsearch'
metrics_path: "/_prometheus/metrics"
static_configs:
- targets:
- "es-master:9200" # Elasticsearch master 节点地址
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 通过监控 Elasticsearch 的 API 获取各种监控指标,并根据阈值规则发出告警,这可以实现对 Elasticsearch 集群状态的实时监控与报警。
通过 Elasticsearch Exporter 来暴露Elasticsearch指标。
安装 Elasticsearch Exporter 以获取 Elasticsearch 集群的 metrics 数据,步骤如下:
(其它安装方式:https://github.com/prometheus-community/elasticsearch_exporter)
wget https://github.com/prometheus-community/elasticsearch_exporter/releases/download/v1.5.0/elasticsearch_exporter-1.5.0.linux-amd64.tar.gz
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 -config.file=elasticsearch_exporter.yml
默认会监听 9114 端口,可以配置web.listen-address启动项修改监听端口。
scrape_configs:
- job_name: elasticsearch
metrics_path: /probe
static_configs:
- targets: ['es1:9114', 'es2:9114'] # 对应 exporter 端口
重启 Prometheus,就可以看到有关 Elasticsearch metrics 的监控数据了。
exporter 支持两种工作模式: