feat: add prometheus support (#474)

This commit is contained in:
Mariano A. Nicolini
2022-12-16 16:21:26 -03:00
committed by GitHub
parent c1f124d3e3
commit 4da574df84
5 changed files with 348 additions and 287 deletions

View File

@ -38,3 +38,5 @@ serde = "1.0"
serde_json = "1.0"
walkdir = "2.3"
futures = "0.3.25"
metrics-exporter-prometheus = { version = "0.11.0", features = ["http-listener"] }
metrics-util = "0.14.0"

View File

@ -1,6 +1,8 @@
//! CLI definition and entrypoint to executable
use clap::{ArgAction, Parser, Subcommand};
use metrics_exporter_prometheus::PrometheusBuilder;
use metrics_util::layers::{PrefixLayer, Stack};
use tracing_subscriber::util::SubscriberInitExt;
use crate::{
@ -16,6 +18,16 @@ pub async fn run() -> eyre::Result<()> {
reth_tracing::build_subscriber(tracing).init();
if opt.metrics {
let (recorder, exporter) =
PrometheusBuilder::new().build().expect("couldn't build Prometheus");
tokio::task::spawn(exporter);
Stack::new(recorder)
.push(PrefixLayer::new("reth"))
.install()
.expect("couldn't install metrics recorder");
}
match opt.command {
Commands::Node(command) => command.execute().await,
Commands::TestEthChain(command) => command.execute().await,
@ -51,4 +63,7 @@ struct Cli {
/// Silence all output
#[clap(long, global = true)]
silent: bool,
#[clap(long, global = true)]
metrics: bool,
}