prometheus 监控之 elasticsearch5.x

本文详细介绍了如何在Elasticsearch中安装和配置监控插件,通过Prometheus进行指标收集,并在Grafana中展示。涵盖了插件安装步骤、Prometheus配置、Grafana图表模板以及预警规则,帮助读者实现全面的Elasticsearch监控。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装监控插件

项目地址:https://github.com/justwatchcom/elasticsearch_exporter
插件下载地址:https://github.com/justwatchcom/elasticsearch_exporter/releases/download/v1.0.4rc1/elasticsearch_exporter-1.0.4rc1.linux-amd64.tar.gz
简单介绍下安装:

[xxx@elk-node1 ~]$ tar zxvf elasticsearch_exporter-1.0.4rc1.linux-amd64.tar.gz
[xxx@elk-node1 ~]$ cd elasticsearch_exporter-1.0.4rc1.linux-amd64/ 
[xxx@elk-node1 ~]$ cp elasticsearch_exporter  /usr/local/bin
[xxx@elk-node1 ~]$ /usr/local/bin/elasticsearch_exporter --web.listen-address "0.0.0.0:9109"  --es.uri http://elastic:changeme@localhost:9200
[xxx@elk-node1 ~]$ curl localhost:9109/metrics

配置prometheus

- job_name: 'elasticsearch'
  file_sd_configs:
  - refresh_interval: 1m
    files:
    - ./conf.d/es*.json

配置consul自动发现请参考:我的另一篇博客

指标解析

参考:
https://grafana.com/dashboards/2322
https://yq.aliyun.com/articles/548354
https://blog.youkuaiyun.com/u013613428/article/details/78179430

指标解析
##搜索和索引性能
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_sumGC run time in seconds垃圾回收时间
elasticsearch_jvm_gc_collection_seconds_countCount of JVM GC runs垃圾搜集数
elasticsearch_jvm_memory_committed_bytesJVM memory currently committed by area最大使用内存限制
elasticsearch_jvm_memory_max_bytes配置的最大jvm值
elasticsearch_jvm_memory_pool_max_bytesJVM内存最大池数
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_bytesJVM memory currently used by area 内存使用量
##集群健康和节点可用性
elasticsearch_cluster_health_status集群状态,green( 所有的主分片和副本分片都正常运行)、yellow(所有的主分片都正常运行,但不是所有的副本分片都正常运行)red(有主分片没能正常运行)值为1的即为对应状态
elasticsearch_cluster_health_number_of_data_nodesnode节点的数量
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_bytesfielddata缓存的大小(字节)
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_percentPercent CPU used by process CPU使用率
elasticsearch_filesystem_data_free_bytesFree space on block device in bytes 磁盘可用空间
elasticsearch_process_open_files_countOpen file descriptors ES进程打开的文件描述符
elasticsearch_transport_rx_packets_totalCount of packets receivedES节点之间网络入流量
elasticsearch_transport_tx_packets_totalCount 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 画图

模版:链接:https://pan.baidu.com/s/1mAtVhko18gD4LxdSkuCGEg 密码:3mtd
在这里插入图片描述

如对你有所帮助 记得点赞呦 ^ _ ^!

### 配置 Prometheus 监控 Elasticsearch #### 安装与配置 Prometheus Elasticsearch Exporter 为了使 Prometheus 能够监控 Elasticsearch,需先安装并配置 Prometheus Elasticsearch Exporter。此工具可以用于监控 Elasticsearch 集群的健康状况、查询性能和资源使用情况[^2]。 ```bash # 下载适合操作系统的版本 wget https://github.com/prometheus/elasticsearch_exporter/releases/download/vX.X.X/elasticsearch_exporter-vX.X.X.linux-amd64.tar.gz tar xvzf elasticsearch_exporter*.tar.gz cd elasticsearch_exporter* ./elasticsearch_exporter --web.listen-address=":9108" ``` 上述命令会启动一个 HTTP 服务,默认监听 `9108` 端口,该端口可按实际需求修改。 #### 修改 Exporter 配置文件 根据具体的监控需求,在 exporter.cfg 文件中定义要抓取的数据项,确保只收集必要的关键指标来减少开销。例如: ```yaml es.uri: "http://localhost:9200/" metrics_path: "/_prometheus/metrics" cluster_health: level: cluster indices_stats: include_indices: ["index_name"] nodes_stats: metrics: ["fs", "jvm", "process", "thread_pool", "transport", "http", "breaker"] ``` 以上 YAML 片段展示了如何指定特定索引名称以及所需节点级别的度量标准。 #### 设置 Prometheus 抓取目标 编辑 Prometheus 的配置文件 prometheus.yml 添加新的 job 来指向已部署好的 Elasticsearch Exporter 实例: ```yaml scrape_configs: - job_name: 'elasticsearch' static_configs: - targets: ['localhost:9108'] ``` 这一步骤使得 Prometheus 开始定期从指定地址拉取数据[^1]。 #### 创建告警规则 利用 Prometheus 提供的强大表达式语言 PromQL 设定合理的阈值触发条件,当满足这些条件时即刻发出通知提醒管理员注意潜在问题的存在。比如检测某个节点是否离线或响应时间超过预期等情形。 ```yaml groups: - name: example rules: - alert: InstanceDown expr: up == 0 for: 5m labels: severity: page annotations: summary: "Instance {{ $labels.instance }} down" ``` 这段配置表示如果某实例连续五分钟未能成功上报状态,则触发名为 “InstanceDown”的警告,并附带简短描述信息给相关人员知晓。 通过遵循上述最佳实践方法论,能够有效地实现对 Elasticsearch 集群的有效监督,及时发现并解决可能出现的各种异常现象,从而保障整个搜索服务平台稳定可靠运行。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值