Prometheus+Grafana+elasticsearch_exporter监控elasticsearch的简单配置过程

一、elasticsearch集群配置

elasticsearch的docker方式安装及golang1.22版本使用elasticsearch7的示例代码-CSDN博客

查找"创建elasticsearch集群"标题即可

服务器集群ip地址:192.168.137.21,192.168.137.22,192.168.137.23

二、启动Prometheus的容器

查看镜像信息

复制代码
[root@ELK ~]# docker images
REPOSITORY                                      TAG       IMAGE ID       CREATED       SIZE
harbor:443/prom/prometheus                      2.54.1    4022a502929b   4 weeks ago   275MB
kibana                                          8.1.3     6bccb01e35af   2 years ago   736MB
harbor:443/library/kibana                       8.1.3     6bccb01e35af   2 years ago   736MB
elasticsearch                                   8.1.3     b543e34fe3ca   2 years ago   1.2GB
harbor:443/library/elasticsearch                8.1.3     b543e34fe3ca   2 years ago   1.2GB
daocloud.io/alpine                              latest    49f356fa4513   3 years ago   5.61MB
docker.elastic.co/elasticsearch/elasticsearch   7.3.0     bdaab402b220   5 years ago   806MB
harbor:443/library/elasticsearch                7.3.0     bdaab402b220   5 years ago   806MB
containerize/elastichd                          latest    c2202f76db37   7 years ago   28.1MB
harbor:443/library/containerize/elastichd       latest    c2202f76db37   7 years ago   28.1MB
harbor:443/library/mobz/elasticsearch-head      5         b19a5c98e43b   7 years ago   824MB
mobz/elasticsearch-head                         5         b19a5c98e43b   7 years ago   824MB

prometheus.yml文件内容:

复制代码
# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
  - job_name: 'es_test'
    static_configs:
      - targets: ['192.168.137.116:9114']

运行Prometheus容器:

复制代码
docker run --name prometheus -v /root/prometheus.yml:/etc/prometheus/prometheus.yml:Z -p 9090:9090 -itd 4022a502929b

三、下载并启动Grafana

复制代码
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.6.2-1.x86_64.rpm
sudo yum install grafana-4.6.2-1.x86_64.rpm

systemctl enable --now grafana-server.service

四、下载elasticsearch_exporter并启动

复制代码
mkdir  /opt/apps
cd /opt/apps

wget  https://github.com/prometheus-community/elasticsearch_exporter/releases/download/v1.3.0/elasticsearch_exporter-1.3.0.linux-amd64.tar.gz

tar -zvxf elasticsearch_exporter-1.3.0.linux-amd64.tar.gz

useradd -M -s /sbin/nologin elastic

systemd配置

如果elasticsearch配置了密码(<es-username>和<es-password>换成真实的用户名,密码):

复制代码
cat > /usr/lib/systemd/system/elasticsearch-exporter.service << "EOF"
# 文件内容如下:
[Unit]
Description=Elasticsearch_Exporter

[Service]
Type=simple
User=elastic
Group=elastic
ExecStart=/opt/apps/elasticsearch_exporter-1.3.0.linux-amd64/elasticsearch_exporter --es.timeout=30s --es.all --es.indices --es.cluster_settings --es.indices_settings --es.shards --es.snapshots --es.uri=http://<es-username>:<es-password>@192.168.137.21:9200
ExecStop= /usr/bin/killall elasticsearch_exporter
Restart=on-failure
RestartSec=3
StartLimitBurst=3
StartLimitInterval=60
WorkingDirectory=/

[Install]
WantedBy=multi-user.target
EOF

如果elasticsearch没有配置密码

复制代码
cat > /usr/lib/systemd/system/elasticsearch-exporter.service << "EOF"
# 文件内容如下:
[Unit]
Description=Elasticsearch_Exporter

[Service]
Type=simple
User=elastic
Group=elastic
ExecStart=/opt/apps/elasticsearch_exporter-1.3.0.linux-amd64/elasticsearch_exporter --es.timeout=30s --es.all --es.indices --es.cluster_settings --es.indices_settings --es.shards --es.snapshots --es.uri=http://192.168.137.21:9200
ExecStop= /usr/bin/killall elasticsearch_exporter
Restart=on-failure
RestartSec=3
StartLimitBurst=3
StartLimitInterval=60
WorkingDirectory=/

[Install]
WantedBy=multi-user.target
EOF

启动elasticsearch-exporter.service

复制代码
systemctl enable --now elasticsearch-exporter.service

elasticsearch_exporter的默认端口是9114,验证是否成功:

复制代码
curl http://192.168.1.86:9114/metrics

五.验证效果

1.查看Prometheus网页效果:

能够模糊搜索elastic条目即可

2.Grafana网页效果

下载模板json文件:

ElasticSearch | Grafana Labs

导入json文件后:

相关推荐
牛奶咖啡1339 分钟前
Prometheus+Grafana构建云原生分布式监控系统(十一)_基于consul的服务发现
云原生·prometheus·consul的安装部署·consul服务自动发现·consul服务的注册删除·consul服务的更新·实现自动去consul注册服务
Otto_10271 天前
在 OpenStack Rocky 中部署 Prometheus + Grafana
openstack·grafana·prometheus
牛奶咖啡131 天前
Prometheus+Grafana构建云原生分布式监控系统(十)_prometheus的服务发现机制(一)
云原生·prometheus·prometheus服务发现·静态服务发现·动态服务发现·基于文件的服务发现配置实践·prometheus标签重写
玄德公笔记1 天前
Prometheus监控k8s的metric详解(第二版)-01-scrape 指标抓取
kubernetes·k8s·prometheus·监控·metric·scrape·k8s监控
小北方城市网1 天前
Spring Boot Actuator+Prometheus+Grafana 生产级监控体系搭建
java·spring boot·python·rabbitmq·java-rabbitmq·grafana·prometheus
牛奶咖啡132 天前
Prometheus+Grafana构建云原生分布式监控系统(九)_pushgateway的使用
云原生·grafana·prometheus·pushgateway·pushgateway使用场景·推数据到pushgateway·pushgateway的使用
AC赳赳老秦3 天前
Notion+DeepSeek:搭建个人工作看板与自动化任务管理规则
前端·javascript·人工智能·自动化·prometheus·notion·deepseek
牛奶咖啡133 天前
Prometheus+Grafana构建云原生分布式监控系统(八)_监控docker容器
云原生·grafana·prometheus·cadvisor·docker容器的安装与部署·docker容器的监控·node-exporter容器
翱翔的苍鹰4 天前
完整的“RNN + jieba 中文情感分析”项目之一:添加 Prometheus + Grafana 监控,配置 CI/CD 自动部署和支持多语言模型切换
rnn·grafana·prometheus
牛奶咖啡134 天前
Prometheus+Grafana构建云原生分布式监控系统(七)
云原生·grafana·prometheus·hadoop集群的安装·hadoop集群的监控·prometheus自动发现·hadoop数据可视化