简介

prometheus获取elasticsearch指标需要借助elasticsearch_exporter

部署

github下载页面:

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

解压到/opt/prometheus/elasticsearch_exporter目录就可以直接运行(如果式解压到其他目录,下面的启动文件也要修改对应的路径)

vim /usr/lib/systemd/system/elasticsearch_exporter.service
[Unit]
Description=elasticsearch_exporter
After=network.target

[Service]
Type=simple
WorkingDirectory=/opt/prometheus/elasticsearch_exporter
ExecStart=/opt/prometheus/elasticsearch_exporter/elasticsearch_exporter --es.all --es.indices --es.cluster_settings --es.indices_settings --es.shards --es.snapshots --es.timeout=10s --web.listen-address=:9114 --web.telemetry-path=/metrics --es.uri http://elastic:xxxxx@192.168.1.200:9200
LimitNOFILE=65536
PrivateTmp=true
RestartSec=2
StartLimitInterval=0
Restart=always

[Install]
WantedBy=multi-user.target

--es.uri 这里如果有验证就写成basic auth的方式,如果没有验证直接写http://192.168.1.200:9200

启动:

systemctl enable elasticsearch_exporter.service
systemctl start elasticsearch_exporter.service

配置prometheus

直接在prometheus.yaml里面加一个job即可。

  - job_name: 'elasticsearch_exporter'
    static_configs:
    - targets: ['127.0.0.1:9114']

重载一下prometheus配置即可生效。

grafana配置

下载压缩包里面有一个dashboard.json的文件就可以grafana的面板JSON

grafana界面左边的菜单:Dashboards –> import ,将JSON文件的内容复制到Import via panel json的输入框,保存即可导入完成。