kona-node: adjusting
log verbosity, filtering log targets, and collecting Prometheus
metrics into Grafana dashboards.
Logging
kona-node provides a -v (or --v) flag as a way to set
the “verbosity” level for logs. By default, the verbosity level
is set to 3, which is the INFO level. The level ranges from 0
being no logs to 5 which includes trace logs. Log levels are
listed below, with each level including the one below it.
5:TRACE- very verbose logs that provide a detailed trace4:DEBUG- logs meant to print debugging information3:INFO- informational logs2:WARN- includes warning and error logs1:ERROR- only error logs are shown0: No logs
-vvv which is the 3 or INFO
level. To set the kona-node to print DEBUG logs or level 4,
run the node like so: kona-node node -vvvv.
Filtering Log Targets
By default, thekona-node initializes its tracing (logging)
using the default environment variable filter provided by the
tracing_subscriber crate. This uses the value in
the RUST_LOG environment variable to set the tracing level
for specific targets. Effectively, RUST_LOG allows you to
bypass the default log level for the whole node or specific
log targets. For example, by prepending RUST_LOG=engine=debug
to the kona-node command (or setting that as an environment
variable), only INFO logs will be displayed except for the
engine log target which will also print DEBUG logs.
This comes in handy say for when we would like to debug Kona’s
P2P stack, we could prepend RUST_LOG=discv5=debug,libp2p=debug
to view debug logs from only discv5 and libp2p targets.
Metrics
Thekona-node can serve Prometheus metrics, which are disabled
by default. To turn them on, pass the --metrics.enabled cli flag.
Unless otherwise specified with the --metrics.port flag, metrics
are exposed on port 9090.
To grab a snapshot of the metrics, you can visit 0.0.0.0:9090
or curl the url.
Grafana and Prometheus
Prometheus is a simple service that scrapes metrics at a predefined interval. Grafana then uses Prometheus as a “Data Source” to visualize the collected metrics. The Reth book provides a great overview to setting up Prometheus and Grafana. Visit the Reth docs to follow along. Thekona-node comes shipped with a default Grafana dashboard
for the kona-node. To import the dashboard to grafana, click
the + icon > Import Dashboard > paste the contents of kona’s
dashboard in the textbox > Load.