6.監控elasticsearch集群---放棄采用(獲取不到數據),建議看另一篇文章:監控elasticsearch


prometheus監控es,同樣采用exporter的方案。

1、安裝部署

現有es三節點的集群,環境大概如下:

主機 組件
192.168.75.11 prometheus
192.168.75.21 es,kibana,nginx

接着分別在如上三台主機上進行如下配置:

wget https://github.com/justwatchcom/elasticsearch_exporter/releases/download/v1.1.0/elasticsearch_exporter-1.1.0.linux-amd64.tar.gz
tar -zxv -f elasticsearch_exporter-1.1.0.linux-amd64.tar.gz
mv elasticsearch_exporter-1.1.0.linux-amd64 /usr/local/elasticsearch_exporter

創建用戶等

groupadd prometheus
useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
chown -R prometheus.prometheus /usr/local/elasticsearch_exporter

啟動監控客戶端:

nohup ./elasticsearch_exporter --web.listen-address ":9308"  --es.uri http://192.168.75.21:9200 &

使用systemd管理:

cat /lib/systemd/system/es_exporter.service

[Unit]
Description=The es_exporter
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/elasticsearch_exporter/elasticsearch_exporter --web.listen-address ":9308" --es.uri http://192.168.75.21:9200
Restart=on-failure

[Install]
WantedBy=multi-user.target

啟動:

systemctl daemon-reload
systemctl start es_exporter
systemctl enable es_exporter

查看metrics:

curl 127.0.0.1:9308/metrics

2,配置 prometheus.yml 添加監控目標

vim /usr/local/prometheus/prometheus.yml

  - job_name: 'elasticsearch'
    scrape_interval: 60s
    scrape_timeout:  30s
    metrics_path: "/metrics"
    static_configs:
    - targets: ['192.168.75.21:9308']
      labels:
       service: elasticsearch

重啟服務。

systemctl restart prometheus

或者通過命令熱加載:

curl  -XPOST localhost:9090/-/reload

5,配置 Grafana 的模板

模板通過json文件進行導入,文件就在解壓的包內。

參考地址:https://shenshengkun.github.io/posts/550bdf86.html

或者通過如下ID進行導入:2322以及其他。


6,開啟認證的啟動方式

如果es開啟了認證,那么啟動的時候需要將用戶名密碼加載進去:

elasticsearch_exporter --web.listen-address ":9308"  --es.uri http://username:password@192.168.75.21:9200 & 

其中使用的是monitoring的用戶密碼。

當然,除去這種命令行的啟動方式之外,還可以像上邊一樣,基於systemd進行管理,只需將認證的參數信息寫入到如下內容當中:

參考網址:https://github.com/justwatchcom/elasticsearch_exporter

cat /etc/default/elasticsearch_exporter

[Unit]
Description=The es_exporter
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/elasticsearch_exporter/elasticsearch_exporter --web.listen-address ":9308" --es.uri=http://username:password@192.168.75.21:9200
Restart=on-failure

[Install]
WantedBy=multi-user.target


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM