prometheus監控es,一樣採用exporter的方案。html
項目地址:linux
elasticsearch_exporter:https://github.com/justwatchcom/elasticsearch_exporternginx
現有es三節點的集羣,環境大概以下:git
主機 | 組件 |
192.168.75.11 | prometheus |
192.168.75.21 | es,kibana,nginxgithub |
接着分別在如上三臺主機上進行以下配置:web
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
建立用戶等json
groupadd prometheus useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus chown -R prometheus.prometheus /usr/local/elasticsearch_exporter
啓動監控客戶端:vim
nohup ./elasticsearch_exporter --web.listen-address ":9308" --es.uri http://192.168.75.21:9200 &
使用systemd管理:curl
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
啓動:elasticsearch
systemctl daemon-reload
systemctl start es_exporter
systemctl enable es_exporter
查看metrics:
curl 127.0.0.1:9308/metrics
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
模板經過json文件進行導入,文件就在解壓的包內。
參考地址:https://shenshengkun.github.io/posts/550bdf86.html
或者經過以下ID進行導入:2322
以及其餘。
若是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