一、安装exporter
elasticsearch_exporter
与ES集群是分开独立的,不需要对原有的ES集群(可能有很多个)做任何修改,不需要重启,只要能访问es集群即可。可以单独部署在一台服务器上
[root@prod-es-master01 ~]# mkdir /opt/soft/
[root@prod-es-master01 ~]# cd /opt/soft/
[root@prod-es-master01 soft]# wget https://github.com/prometheus-community/elasticsearch_exporter/releases/download/v1.3.0/elasticsearch_exporter-1.3.0.linux-amd64.tar.gz
[root@prod-es-master01 soft]# tar -zxvf elasticsearch_exporter-1.3.0.linux-amd64.tar.gz -C /usr/local/
[root@prod-es-master01 soft]# cd /usr/local/
[root@prod-es-master01 local]# mv elasticsearch_exporter-1.3.0.linux-amd64 elasticsearch_exporter
二、启动exporter
1、常用参数解释
参数选项 | 参数说明 |
–es.uri | 默认http://localhost:9200,连接到的Elasticsearch节点的地址(主机和端口) |
–es.all | 默认flase |
–es.cluster_settings | 默认flase,如果为true,请在统计信息中查询集群设置 |
–es.indices | 默认flase,如果为true,则查询统计信息以获取集群中的所有索引 |
–es.indices_settings | 默认flase,如果为true,则查询集群中所有索引的设置统计信息 |
–es.shards | 默认flase,如果为true,则查询集群中所有索引的统计信息,包括分片级统计信息 |
–es.snapshots | 默认flase,如果为true,则查询集群快照的统计信息 |
2、Systemd管理
vim /lib/systemd/system/es_exporter.service
[Unit]
Description=The es_exporter
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/elasticsearch_exporter/elasticsearch_exporter --es.all --es.indices --es.cluster_settings --es.indices_settings --es.shards --es.snapshots --es.uri http://elastic:T6dc7aY1mLTP9NtK3sX4@192.168.66.86:9200
Restart=on-failure
[Install]
WantedBy=multi-user.target
注意:es集群开启了x-pack验证则需要使用用户名和密码,反之不需要
3、启动服务
systemctl daemon-reload
systemctl start es_exporter
systemctl enable es_exporter
4、检查数据
- 现在通过curl去访问9114端口去检查数据
[root@prod-es-master01 ~]# curl 127.0.0.1:9114/metrics

三、配置监控Job
1、配置prometheus监控
~]# vim /usr/local/prometheus/prometheus.yml
## elasticsearch Cluster
- job_name: "elasticsearch Cluster"
scrape_interval: 60s
scrape_timeout: 60s
static_configs:
- targets: ['192.168.66.86:9114']
relabel_configs:
- source_labels: [__address__]
regex: '(.*)\:9114'
target_label: 'nodeip'
replacement: '$1'
- source_labels: [__address__]
regex: '(.*)\:9114'
target_label: 'hostname'
replacement: '$1'
#重载prometheus配置
~]# promtool check config /usr/local/prometheus/prometheus.yml
~]# curl -X POST http://127.0.0.1:9090/-/reload
- 检查Targets

2、添加Grafana监控面板

- 节点跳转链接URL修改

- 格式:URL:https://你的Grafana访问域名/d/5b64379ae97d471bb733c16fa5494f98/elasticsearch-node-stats?var-cluster=$cluster&var-name=${__cell}

四、告警规则创建
~]# vim /usr/local/prometheus/rules/alerts_es.yml
