Elasticsearch_exporter + Prometheus + Grafana监控之搭建梳理

发布时间 2023-10-23 14:19:40作者: 記憶や空白

一、安装elasticsearch_exporter并启动

1.1 官网下载elasticsearch_exporter的安装包,地址如下:

如果是Linux系统,建议安装此版本:elasticsearch_exporter-1.3.0.linux-amd64.tar.gz

https://github.com/prometheus-community/elasticsearch_exporter/releases

1.2 上传安装包到服务器,并解压:

tar -xvf elasticsearch_exporter-1.3.0.linux-amd64.tar.gz -C /opt/   ###-C是指定解压目录

1.3 启动elasticsearch_exporter(有两种启动方法):

方法1:

cd /opt/elasticsearch_exporter-1.3.0/
nohup ./elasticsearch_exporter --es.all --es.indices --es.cluster_settings --es.node="daily_test" --es.indices_settings --es.shards --es.snapshots --es.timeout=5s --web.listen-address ":9555" --web.telemetry-path "/metrics" --es.ssl-skip-verify --es.clusterinfo.interval=5m --es.uri https://用户:口令@IP:端口 &
tail -f nohup.out   ###查看日志,是否正常运行

注:

  1. --web.listen-address ":9555",指定监听的端口,不与现有端口冲突的前提下,可随便设置;还可以通过设置不用的监听端口,来启动多个实例,适用于监控不同的elasticsearch集群的场景
  2. --es.uri 此参数后若衔接的是https协议,则使用上面代码中的格式;若是http协议,则用:http://IP:端口 ,即可。需要注意的是,这里的IP地址是指elasticsearch集群中某一台服务器的ip地址
  3. 该启动方法的优点在于,可启动多个不同端口的进程

方法2:

cd /lib/systemd/system/      ###配置服务的目录
vim elasticsearch_exporter.service     ###写入如下内容

[Unit]
Description=elasticsearch_exporter
After=syslog.target network.target
[Service]
Type=simple
RemainAfterExit=no
WorkingDirectory=/opt/elasticsearch_exporter-1.3.0/
User=root
Group=root
ExecStart=/root/elasticsearch_exporter-1.3.0/elasticsearch_exporter  --es.all --es.indices --es.cluster_settings --es.node="daily_test" --es.indices_settings --es.shards --es.snapshots --es.timeout=5s --web.listen-address ":9555" --web.telemetry-path "/metrics" --es.ssl-skip-verify --es.clusterinfo.interval=5m --es.uri http://用户:口令@IP:端口
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target

配置开机自启,并启动:

systemctl daemon-reload
systemctk enable elasticsearch_exporter
systemctl start elasticsearch_exporter
systemctl status elasticsearch_exporter

查看抓取到的信息

curl http://ip:端口/metrics  #注意这里的IP指的是elasticsearch_exporter服务器的地址,端口是监听端口

prothemous配置文件

  • job_name: 'wms-es'
    metrics_path: '/metrics'
    static_configs:
    • targets: ['10.250.0.19:9555']
      labels:
      instance: 10.250.0.19:9555

重启服务生效

Grafana

导入模板:2322

告警规则

groups:
   - name: ElasticSearch服务监控
     rules:
     - alert: ES集群节点减少
       expr: elasticsearch_cluster_health_number_of_nodes < 3  #ES集群节点数3
       for: 5m
       labels:
         severity: 严重告警
       annotations:
         summary: "ES集群节点减少:{{$.Labels.job}}"
         description: "ES集群节点数减少:{{$.Labels.job}},(当前:{{$value}})"
    
     - alert: jvm内存使用率告警
       expr: elasticsearch_jvm_memory_used_bytes{area="heap"} / elasticsearch_jvm_memory_max_bytes{area="heap"}*100 > 90
       for: 5m
       labels:
         severity: 严重告警
       annotations:
         summary: "jvm内存使用率过高:{{$.Labels.job}}"
         description: "jvm内存使用率过高:{{$.Labels.job}}大于90%,(当前:{{$value}})"