写点什么

Prometheus Exporter (十三)Elasticsearch Exporter

作者:耳东@Erdong
  • 2021 年 11 月 27 日
  • 本文字数:2204 字

    阅读完需:约 7 分钟

Prometheus Exporter (十三)Elasticsearch Exporter

本文已经收录在 Prometheus 合集 Prometheus 都可以采集那些指标?-- 常用 Exporter 合集 中。


Elasticsearch 是一个实时的分布式存储、搜索、分析的引擎,官网是 https://www.elastic.co/cn/elasticsearch/ 。 很多公司在用这个,你的公司大概率也有,那么对于 Elasticsearch 该怎么监控呢?针对这个问题,Prometheus Community 开发了一个 Elasticsearch Exporter ,用来导出 Elasticsearch 的监控数据,仓库地址是https://github.com/prometheus-community/elasticsearch_exporter ,用 Golang 编写。


Elasticsearch Exporter 当前版本是 1.3.0 ,发布于 2021.10.21

安装和配置

安装是比较简单的,下载最新版本的二进制包,或者下载 Docker image 。启动 Docker image 可以使用


docker run --rm -p 9114:9114 quay.io/prometheuscommunity/elasticsearch-exporter:latest --es.uri=http://localhost:9200 
复制代码


在 Kubernetes 里使用 helm 部署可以参考 https://github.com/kubernetes/charts/tree/master/stable/elasticsearch-exporter


每次从这个 Exporter 获取 Elasticsearch 的监控数据都会从 Elasticsearch 服务拉取一次,如果获取时间间隔太短的话,可能会增大服务端的压力,尤其是使用 --es.all--es.indices 运行 Exporter 的时候。所以在实际使用过程中,建议大家在确定获取数据间隔的时候,先测量获取 /_nodes/stats/_all/_stats 指标的时间,防止监控对服务造成影响。


Elasticsearch Exporter 启动的时候有如下启动参数可以选择。


  • es.uri Address (host and port) of the Elasticsearch node we should connect to. This could be a local node (localhost:9200, for instance), or the address of a remote Elasticsearch server. When basic auth is needed, specify as: <proto>://<user>:<password>@<host>:<port>. E.G., http://admin:pass@localhost:9200. Special characters in the user credentials need to be URL-encoded.

  • es.all If true, query stats for all nodes in the cluster, rather than just the node we connect to.

  • es.cluster_settings If true, query stats for cluster settings.

  • es.indices If true, query stats for all indices in the cluster.

  • es.indices_settings If true, query settings stats for all indices in the cluster.

  • es.indices_mappings If true, query stats for mappings of all indices of the cluster. |false

  • es.shards If true, query stats for all indices in the cluster, including shard-level stats (implies es.indices=true).

  • es.snapshots If true, query stats for the cluster snapshots.

  • es.timeout Timeout for trying to get stats from Elasticsearch. (ex: 20s)

  • es.ca Path to PEM file that contains trusted Certificate Authorities for the Elasticsearch connection.

  • es.client-private-key Path to PEM file that contains the private key for client auth when connecting to Elasticsearch.

  • es.client-cert Path to PEM file that contains the corresponding cert for the private key to connect to Elasticsearch.

  • es.clusterinfo.interval Cluster info update interval for the cluster label

  • es.ssl-skip-verify Skip SSL verification when connecting to Elasticsearch.

  • es.apiKey API Key to use for authenticating against Elasticsearch.

  • web.listen-address Address to listen on for web interface and telemetry. 缺省是:9114

  • web.telemetry-path Path under which to expose metrics. 缺省是 /metrics

  • version Show version info on stdout and exit.


命令行参数以单个参数开始,用于版本低于 1.1.0rc1 。对于大于 1.1.0rc1 的版本,命令行参数用 -- 指定。此外,所有命令行参数都可以作为环境变量提供。


对于 Elasticsearch 7.x 版本提供了一些安全性的措施,支持 RBAC,用户名和密码可以直接在 URI 中传递,也可以通过`ES_USERNAME`和`ES_PASSWORD`环境变量传递。如果在 URI 中传递了身份验证,那么指定这两个环境变量以后将覆盖 URI 里的内容。


指标


Elasticsearch Exporter 可以导出很多指标,部分指标如下所示:


  • elasticsearch_breakers_estimated_size_bytes | gauge | Estimated size in bytes of breaker

  • elasticsearch_breakers_limit_size_bytes | gauge | Limit size in bytes for breaker

  • elasticsearch_breakers_tripped | counter | tripped for breaker

  • elasticsearch_cluster_health_active_primary_shards | gauge | The number of primary shards in your cluster. This is an aggregate total across all indices.

  • elasticsearch_cluster_health_active_shards | gauge | Aggregate total of all shards across all indices, which includes replica shards.

  • elasticsearch_cluster_health_delayed_unassigned_shards | gauge | Shards delayed to reduce reallocation overhead

  • elasticsearch_cluster_health_initializing_shards | gauge | Count of shards that are being freshly created.

  • elasticsearch_cluster_health_number_of_data_nodes | gauge | Number of data nodes in the cluster.


全部的指标大约有 120+ 条以上,详细指标可以参考 https://github.com/prometheus-community/elasticsearch_exporter#metrics

发布于: 2021 年 11 月 27 日阅读数: 15
用户头像

耳东@Erdong

关注

还未添加个人签名 2020.05.24 加入

主要研究分享运维技术,专注于监控、CICD、操作系统、云原生领域,公众号【耳东学堂】,知识星球同名,坚持原创,希望能和大家在运维路上结伴而行 邮箱:erdong@mail.erdong.site

评论

发布
暂无评论
Prometheus Exporter (十三)Elasticsearch Exporter