Prometheus监控平台配置Elasticsearch
1. 前言
elasticsearch-prometheus-exporter是ES用于Prometheus exporter的插件,可以通过给elasticsearch安装这个插件并配置Prometheus来完成Prometheus监控elasticsearch。
版本:version 1.1.0
2. 安装配置elasticsearch_exporter
2.1 下载
,也可以wget在线下载,这里我下载到了home目录下
# wget https://github.com/justwatchcom/elasticsearch_exporter/releases/download/v1.1.0/elasticsearch_exporter-1.1.0.linux-amd64.tar.gz
2.2 解压/usr/local目录下,并重命名
# tar -zxvf elasticsearch_exporter-1.1.0.linux-amd64.tar.gz -C /usr/local/
# cd /usr/local/
# mv elasticsearch_exporter-1.1.0.linux-amd64/ elasticsearch_exporter
2.3 启动
注意:只要设置不同的--web.listen-address监听端口,可启动多个实例,分别监控不同的ES集群。
前台启动,默认监听端口9114
# ./elasticsearch_exporter --web.listen-address=":9114" --es.uri http://172.20.32.218:9200
后台启动
# nohup ./elasticsearch_exporter --web.listen-address=":9114" --es.uri http://172.20.32.218:9200 &
完整参数启动方式:
nohup ./elasticsearch_exporter --es.all --es.indices --es.cluster_settings --es.indices_settings --es.shards --es.snapshots --es.timeout=10s --web.listen-address=":9114" --web.telemetry-path="/metrics" --es.uri http://172.20.32.218:9200 &
参数说明: --es.uri 默认http://localhost:9200,连接到的Elasticsearch节点的地址(主机和端口)。 这可以是本地节点(例如localhost:9200),也可以是远程 Elasticsearch服务器的地址 --es.all 默认flase,如果为true,则查询群集中所有节点的统计信息,而不仅仅是查询我们连接到的节点。 --es.cluster_settings 默认flase,如果为true,请在统计信息中查询集群设置 --es.indices 默认flase,如果为true,则查询统计信息以获取集群中的所有索引。 --es.indices_settings 默认flase,如果为true,则查询集群中所有索引的设置统计信息。 --es.shards 默认flase,如果为true,则查询集群中所有索引的统计信息,包括分片级统计信息(意味着es.indices = true)。 --es.snapshots 默认flase,如果为true,则查询集群快照的统计信息。
2.4 加入开机自启
cat > /etc/systemd/system/elasticsearch_exporter.service << "EOF" [Unit] Description=elasticsearch_exporter After=local-fs.target network-online.target network.target Wants=local-fs.target network-online.target network.target [Service] ExecStart=/usr/local/elasticsearch_exporter/elasticsearch_exporter --es.all --es.indices --es.cluster_settings --es.indices_settings --es.shards --es.snapshots --web.listen-address ":9114" --es.timeout 20s --es.uri http://172.20.32.218:9200 Restart=on-failure [Install] WantedBy=multi-user.target EOF
# systemctl daemon-reload
# systemctl enable elasticsearch_exporter
# systemctl start elasticsearch_exporter
# systemctl status elasticsearch_exporter
2.5 浏览器访问
也可以通过,看抓取的指标信息。
3. Prometheus配置
3.1 进入prometheus安装目录,编辑prometheus.yml
# vim prometheus.yml //加入prometheus监控中,targets可配置多个监控目标
- job_name: elasticsearch scrape_interval: 60s scrape_timeout: 30s metrics_path: "/metrics" static_configs: - targets: [172.20.32.218:9114]
3.2 重启Prometheus
# systemctl restart prometheus
浏览器查看监控信息:
注:State=UP,说明成功
4. Grafana配置
浏览器访问:
导入官方模板 ,可在查看模板编号2322或者266其它,如果内网环境建议可下载后导入。
修改模板信息Prometheus
配置完之后,查看仪表盘,就能自动读取prometheus存储的数据