Use metrics to monitor node performance
To enable the Prometheus monitoring and alerting service to access Hyperledger Besu metrics, use the --metrics-enabled
option. Use Grafana to visualize the collected data. See the sample Besu Full Grafana dashboard.
The Besu example networks have monitoring with Prometheus and Grafana configured.
Use Prometheus to monitor the number of blocks your Besu node is behind the chain head, and to alert you that your node is not keeping up with the chain head.
This recording shows examples of monitoring Hyperledger Besu.
Install Prometheus
To use Prometheus with Besu, install the Prometheus main component. On MacOS, install with Homebrew:
brew install prometheus
You can also install:
- Exporters that send system metrics to Prometheus to monitor non-Besu-specific items such as disk and CPU usage.
- Other Prometheus components, such as the Alert Manager. Additional configuration is not required for these components because Prometheus handles and analyzes data directly from the feed.
Set up and run Prometheus with Besu
To configure Prometheus and run with Besu:
-
Configure Prometheus to poll Besu. For example, add the following YAML fragment to the
scrape_configs
block of theprometheus.yml
file:- Fragment to insert in prometheus.yml
- Full prometheus.yml example
- job_name: besu
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- localhost:9545global:
scrape_interval: 15s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: besu
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- localhost:9545Prometheus requires 3 MB of space per node per hour for metrics, with a
scrape_interval
of 15 seconds. -
Start Besu with the
--metrics-enabled
option. To start a single node for testing with metrics enabled, run the following command:- Syntax
- Example
besu --network=dev --miner-enabled --miner-coinbase <COINBASE ADDRESS> --rpc-http-cors-origins="all" --rpc-http-enabled --metrics-enabled
besu --network=dev --miner-enabled --miner-coinbase fe3b557e8fb62b89f4916b721be55ceb828dbd73 --rpc-http-cors-origins="all" --rpc-http-enabled --metrics-enabled
To specify the host and port on which Prometheus accesses Besu, use the
--metrics-host
and--metrics-port
options. The default host and port are127.0.0.1
(localhost
) and9545
.dangerTo avoid DNS rebinding attacks, if running Prometheus on a different host than your Besu node (any host other than
localhost
), add the hostname that Prometheus uses to--host-allowlist
. For example, if Prometheus is configured to get metrics fromhttp://besu.local:8008/metrics
, thenbesu.local
must be in--host-allowlist
. -
In another terminal, run Prometheus specifying the
prometheus.yml
file:prometheus --config.file=prometheus.yml
-
View the Prometheus graphical interface.
tipUse a log ingestion tool, such as Logstash, to parse the logs and alert you to configured anomalies.
Run Prometheus with Besu in push mode
The --metrics-enabled
option enables Prometheus
polling of Besu, but sometimes metrics are hard to poll (for example, when running inside Docker
containers with varying IP addresses).
To enable Besu to push metrics to a Prometheus push gateway,
use the --metrics-push-enabled
option.
To configure Prometheus and run with Besu pushing to a push gateway:
-
Configure Prometheus to read from a push gateway. For example, add the following YAML fragment to the
scrape_configs
block of theprometheus.yml
file:- job_name: push-gateway
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- localhost:9091 -
Start the push gateway. You can deploy the push gateway using the Docker image:
docker pull prom/pushgateway
docker run -d -p 9091:9091 prom/pushgateway -
Start Besu specifying the
--metrics-push-enabled
option and port of the push gateway:- Syntax
- Example
besu --network=dev --miner-enabled --miner-coinbase <COINBASE ADDRESS> --rpc-http-cors-origins="all" --rpc-http-enabled --metrics-push-enabled --metrics-push-port=9091 --metrics-push-host=127.0.0.1
besu --network=dev --miner-enabled --miner-coinbase fe3b557e8fb62b89f4916b721be55ceb828dbd73 --rpc-http-cors-origins="all" --rpc-http-enabled --metrics-push-enabled --metrics-push-port=9091 --metrics-push-host=127.0.0.1
-
In another terminal, run Prometheus specifying the
prometheus.yml
file:prometheus --config.file=prometheus.yml
-
View the Prometheus graphical interface.
View Prometheus graphical interface
-
Open a Web browser to
http://localhost:9090
to view the Prometheus graphical interface. -
Choose Graph from the menu bar and click the Console tab below.
-
From the Insert metric at cursor drop-down, select a metric such as
besu_blockchain_difficulty_total
orethereum_blockchain_height
and click Execute. The values display. -
Click the Graph tab to view the data as a time-based graph. The query string displays below the graph. For example,
{ethereum_blockchain_height{instance="localhost:9545",job="prometheus"}
.
View the metrics list
Run the following command to view the full list of available metrics:
curl http://localhost:9545/metrics
Update the host and port if you are not using the default values.
Each metric, such as besu_blockchain_chain_head_gas_limit
, starts with a metric category prefix.
Metrics specific to Besu use the besu_
prefix, followed by another metric category.
You can enable metric categories using the
--metrics-category
command line option.