Prometheus / 监控平台 / 系统运维

Prometheus监控ES集群

浅时光博客 · 12月27日 · 2021年 · 6.7w 次已读
Elasticsearch告警规则
价格:免费
  • 终身VIP购买价格 : 免费
信息ES告警规则
文件YAML
最近更新2021年12月27日

一、安装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原文链接:https://dqzboy.com,如果为true,则查询群集中所有节点的统计信息,而不仅仅是查询我们连接到的节点
–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

本文作者:浅时光博客
原文链接:https://www.dqzboy.com/9494.html
版权声明:知识共享署名-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)协议进行许可,转载时请以>超链接形式标明文章原始出处和作者信息
免责声明:本站内容仅供个人学习与研究,严禁用于商业或非法目的。请在下载后24小时内删除相应内容。继续浏览或下载即表明您接受上述条件,任何后果由用户自行承担。