转载自:https://blog.csdn.net/u010453363/article/details/76689435/
用prometheus主要是监控elk中的elasticsearch和logstash
prometheus的clicent收集数据,并提供http服务,由prometheus server主动pull数据。
1.1 elasticsearch数据由es插件
实现: https://github.com/vvanholl/elasticsearch-prometheus-exporter
1.1.1 插件下载
目前试用的是es5.4,https://github.com/vvanholl/elasticsearch-prometheus-exporter/releases 下载对应版本的插件
1.1.2 安装插件
sh ./bin/elasticsearch-plugin install file:///home/elk/elasticsearch-prometheus-exporter-5.4.0.0.zip ,重启es。
默认指标目录:http://192.168.x.x:9200/_prometheus/metrics
http://192.168.x.x:9200/_prometheus/metrics能够看到es的prometheus指标,说明插件安装成功。
http://192.168.x.x:9200/_prometheus/metrics能够看到es的prometheus指标,说明插件安装成功。
1.2配置prometheus server 来pull es数据
# 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).
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).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first.rules"
# - "second.rules"
# - "prometheus.rules"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# es motitor
- job_name: elasticsearch
scrape_interval: 10s
metrics_path: "/_prometheus/metrics"
static_configs:
- targets: ['192.168.x.x:9200']
rule_files:
# - "first.rules"
# - "second.rules"
# - "prometheus.rules"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# es motitor
- job_name: elasticsearch
scrape_interval: 10s
metrics_path: "/_prometheus/metrics"
static_configs:
- targets: ['192.168.x.x:9200']
ps:es指标的路径必须为/_prometheus/metrics ,否则prometheus server拉取不到es的指标数据。
到此 prometheus能够正常展示es指标。