You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Prometheus指标在Grafana中计算展示Elasticsearch核心性能指标

多索引多节点场景下的Elasticsearch关键指标PromQL计算方案

1. 索引速率(Indexing Rate)

  • 指标说明:对应Kibana中每秒新增的文档数,需聚合所有节点、所有索引的写入请求
  • PromQL(按索引拆分):
sum(rate(elasticsearch_indices_indexing_index_total[1m])) by (index)
  • PromQL(全局总速率):
sum(rate(elasticsearch_indices_indexing_index_total[1m]))
  • 注意:用elasticsearch_indices_indexing_index_total(文档写入总数)的速率计算,聚合所有节点和索引避免统计偏差;时间窗口选1m和Kibana默认统计周期对齐,减少数值差异。

2. 索引延迟(Indexing Latency)

  • 指标说明:对应Kibana中文档写入的平均延迟,取所有索引写入请求的平均耗时
  • PromQL(按索引拆分):
sum(rate(elasticsearch_indices_indexing_index_time_in_millis_total[1m])) by (index) / sum(rate(elasticsearch_indices_indexing_index_total[1m])) by (index)
  • PromQL(全局平均延迟):
sum(rate(elasticsearch_indices_indexing_index_time_in_millis_total[1m])) / sum(rate(elasticsearch_indices_indexing_index_total[1m]))
  • 注意:通过总耗时除以总请求数得到平均延迟,确保覆盖所有节点和索引的写入数据。

3. 搜索速率(Search Rate)

  • 指标说明:对应Kibana中每秒的搜索请求数,需覆盖所有节点、所有索引的查询(含query和fetch两个阶段)
  • PromQL(按索引拆分):
sum(rate(elasticsearch_indices_search_query_total[1m])) by (index) + sum(rate(elasticsearch_indices_search_fetch_total[1m])) by (index)
  • PromQL(全局总速率):
sum(rate(elasticsearch_indices_search_query_total[1m])) + sum(rate(elasticsearch_indices_search_fetch_total[1m]))
  • 注意:ES搜索分为query和fetch两个阶段,Kibana统计的是两者总和,需将两个指标的速率相加避免漏统计。

4. 搜索延迟(Search Latency)

  • 指标说明:对应Kibana中搜索请求的平均延迟,计算所有搜索请求的平均耗时
  • PromQL(按索引拆分):
(sum(rate(elasticsearch_indices_search_query_time_in_millis_total[1m])) by (index) + sum(rate(elasticsearch_indices_search_fetch_time_in_millis_total[1m])) by (index)) / (sum(rate(elasticsearch_indices_search_query_total[1m])) by (index) + sum(rate(elasticsearch_indices_search_fetch_total[1m])) by (index))
  • PromQL(全局平均延迟):
(sum(rate(elasticsearch_indices_search_query_time_in_millis_total[1m])) + sum(rate(elasticsearch_indices_search_fetch_time_in_millis_total[1m]))) / (sum(rate(elasticsearch_indices_search_query_total[1m])) + sum(rate(elasticsearch_indices_search_fetch_total[1m])))
  • 注意:需将query和fetch阶段的总耗时相加,再除以总请求数,确保和Kibana的统计逻辑一致。

常见偏差原因

  1. 未聚合多节点/多索引:仅统计单个节点或索引会导致数值远低于真实值
  2. 忽略搜索双阶段:仅统计query或fetch单一阶段会造成速率、延迟偏差
  3. 时间窗口不匹配:Kibana默认用1分钟统计周期,PromQL的rate窗口需保持一致
  4. 指标维度错误:误用节点级指标(如elasticsearch_indexing_total)而非索引级指标,会导致统计维度不对

内容的提问来源于stack exchange,提问作者xni28943

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 20:12:48