Zookeeper provided “metrics provider” such a way user can monitor zookeeper. Prometheus is one of the monitoring services can be used to monitor zookeeper.
The following are the steps to enable metrics provider in Zookeeper.
Configure Metrics provider in Zookeeper configuration.
Install “Prometheus” service
Software’s and Tools
Windows 10 Java 1.8 or higher Zookeeper 3.7.0 prometheus-2.28.1 |
Prerequisite
Setup a Zookeeper cluster
http://www.liferaysavvy.com/2021/07/setup-zookeeper-cluster.html
Configure Metrics provider in Zookeeper configuration.
Open “zoo.cfg” file and update with metric provider configuration.
Zookeeper Node1
## Metrics Providers # https://prometheus.io Metrics Exporter metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider metricsProvider.httpPort=7001 metricsProvider.exportJvmInfo=true |
Zookeeper Node2
## Metrics Providers # https://prometheus.io Metrics Exporter metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider metricsProvider.httpPort=7002 metricsProvider.exportJvmInfo=true |
Zookeeper Node3
## Metrics Providers # https://prometheus.io Metrics Exporter metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider metricsProvider.httpPort=7003 metricsProvider.exportJvmInfo=true |
Start all Zookeeper server and make sure all are starting successfully.
Install “Prometheus” service
Go to Prometheus download page and download latest version.
https://prometheus.io/download/
Direct Links as follows
Extract in local Drive
Configure Zookeeper cluster in Prometheus
Create “metrics-zk.yaml” file in root directory of “Prometheus” and set Prometheus's scraper to target the Zookeepercluster endpoints.
Add following configuration in “metrics-zk.yaml” file and make sure target property should have zookeeper cluster hosts with metrics port that enabled in “zoo.cfg”
# 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: 'zookeepermetrics' #metrics_path: '/zookeeper-metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:7001','localhost:7002','localhost:7003'] |
Start “Prometheus”
Open command prompt and locate to “Prometheus” root directory. Use following start command and pass web listen address and config file as options.
prometheus.exe --config.file metrics-zk.yaml --web.listen-address ":9090" --storage.tsdb.path "metrics-zk.data" |
Verify Installation
Access “Prometheus” web interface with following URL and its running on 9090 port.
Targets Status
Go to Status menu and click on targets so we can see Zookeeper cluster health for each node.
Zookeeper node’s health in the cluster.
Reference