使用Promethues+Grafana监控Elasticsearch

6 篇文章 0 订阅
1 篇文章 0 订阅

监控选用说明

虽然用Kibana来监控ES,能展示一些关键指标,但ES本身收集的指标并不全面,还需要在ES配置文件中设置xpack.monitoring.collection.enabled: true来开启监控指标的收集,并占用额外的集群资源。重点是当集群出故障时,故障期间可能也收集不到监控指标。

所以需要使用第三方监控组件来实现对ES的监控。目前开源监控组件最受欢迎的就是Promethues+Grafana,再使用elasticsearch-exportor从ES中获取监控指标,最终就可以通过Grafana来展示各种监控图表了。

指标上报流程说明

promethues、elasticsearch-exportor和grafana完成上报的流程如下图所示:
在这里插入图片描述

  1. elasticsearch-exportor通过elasticsearch的Rest Api周期性获取ES集群的各项指标,组装成promethues支持解析的指标数据格式,并暴露http端口来支持通过http的方式获取这些指标数据;
  2. promethues通过elasticsearch-exportor提供的http接口来获取指标数据;
  3. grafana使用promethues上的指标数据绘图展示监控面板。

实现监控的步骤

使用环境:centos7.9
部署方式:通过docker compose

搭建elasticsearch-exporter服务

1、创建elasticsearch-exportor目录

mkdir /home/es/elasticsearch_exporter

2、编写docker-compose.yml

cd /home/es/elasticsearch_exporter
vim docker-compose.yml

docker-compose.yml文件内容

version: '2.1'

services:  
  elasticsearch_exporter:
    image: quay.io/prometheuscommunity/elasticsearch-exporter:latest
    command:
      - '--es.uri=http://192.168.8.87:9200'  # 内网IP
    restart: unless-stopped   # 表示容器退出时总是重启,但是不考虑docker守护进程运行时就已经停止的容器
    ports:
      - 9114:9114     

3、启动服务

cd /home/prome
# 后台启动
docker compose up -d 

4、确认elasticsearch-exporter成功连上了es

通过http请求获取metric来验证elasticsearch-exporter是否连上了

例如:http://192.168.8.87:9114/metrics

如果返回了elasticsearch_开头的相关的监控指标,则说明elasticsearch-exporter成功连接了elasticsearch
在这里插入图片描述

搭建promethues和grafana服务

1、创建目录

mkdir /home/prome

2、编写docker-compose.yml

cd /home/prome
vim docker-compose.yml

docker-compose.yml文件内容

version: '2.1'

networks:
  monitor-net:
    driver: bridge

volumes:
    prometheus_data: {}
    grafana_data: {}

services:
  prometheus:
    image: prom/prometheus:v2.37.0
    container_name: prometheus
    volumes:
      - ./prometheus:/etc/prometheus
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--storage.tsdb.retention.time=200h'
      - '--web.enable-lifecycle'
    restart: unless-stopped   # 表示容器退出时总是重启,但是不考虑docker守护进程运行时就已经停止的容器
    ports:
      - 9090:9090
    networks:
      - monitor-net
    labels:
      org.label-schema.group: "monitoring"

  grafana:
    image: grafana/grafana:9.0.3
    container_name: grafana
    volumes:
      - grafana_data:/var/lib/grafana
      - ./grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards
      - ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources
    environment:
      - GF_SECURITY_ADMIN_USER=${ADMIN_USER:-admin}
      - GF_SECURITY_ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin123}
      - GF_USERS_ALLOW_SIGN_UP=false
    restart: unless-stopped
    ports:
      - 3000:3000
    networks:
      - monitor-net
    labels:
      org.label-schema.group: "monitoring"

3、启动服务

cd /home/prome
# 后台启动
docker compose up -d 

4、配置拉取 elasticsearch-exporter的监控数据

修改配置文件 ./prometheus/prometheus.yml,在其末尾增加elasticsearch-exporter的地址配置,如下:

- job_name: 'es_test'      
    static_configs:
      - targets: ['192.168.1.86:9114']

如图(需要注意yml文件的层级关系):
在这里插入图片描述
5、确认prometheus成功连上了elasticsearch-exporte

浏览器访问 IP:9090/status 进入到prometheus提供的web界面

例如:http://192.168.8.87:9090/status

看到如下页面,表示prometheus已启动成功
在这里插入图片描述
点击菜单栏的Graph,在这个页面可以查询到prometheus获取到的指标
prometheus成功连上了elasticsearch-exporte的现象:

(1)输入“el”可以出来选项
在这里插入图片描述
(2)查询其中一个指标,有如下展示:
在这里插入图片描述

在这里插入图片描述
6、访问浏览器访问IP:3000/进入grafana登录页面
例如:http://192.168.8.87:3000/

7、输入管理员账号密码(docker-compose.yml里配置的)
账号:admin
密码:admin123

8、导入仪表盘
grafana官网提供了elasticsearch-exportor上报指标的仪表盘,包含了上报到elasticsearch相关指标的监控图,可直接到官网下载后导入即可使用

下载页面为:
https://grafana.com/grafana/dashboards
右边列表可自选仪表盘
在这里插入图片描述

选择某个进入详情后,点击右侧的Download JSON即可下载
ps. 需要尝试几个,可能会导致部分监控面板无法正常显示。

本次记录我选择的是:

https://grafana.com/grafana/dashboards/17724-elasticsearch/
在这里插入图片描述
下载完成后,回到部署的Grafana服务里,在左侧展开的菜单栏中点击Dashboards下的Import
在这里插入图片描述
上传下载的json文件
在这里插入图片描述
点击Import即可导入仪表盘
在这里插入图片描述
在这里插入图片描述
点击左侧搜索框也可进入导入的面板
在这里插入图片描述

  • 27
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值