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

615
Cargo.lock generated

File diff suppressed because it is too large Load Diff

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,
}

View File

@ -27,6 +27,7 @@ pin-project = "1.0"
tracing = "0.1.37"
snap = "1.0.5"
smol_str = { version = "0.1", features = ["serde"] }
metrics = "0.20.1"
[dev-dependencies]
test-fuzz = "3.0.4"

View File

@ -7,6 +7,7 @@ use crate::{
};
use bytes::{Buf, Bytes, BytesMut};
use futures::{Sink, SinkExt, StreamExt};
use metrics::counter;
use pin_project::pin_project;
use reth_rlp::{Decodable, DecodeError, Encodable, EMPTY_STRING_CODE};
use serde::{Deserialize, Serialize};
@ -119,6 +120,7 @@ where
let reason = DisconnectReason::try_from(disconnect_id)?;
tracing::error!("Disconnected by peer during handshake: {}", reason);
counter!("p2pstream.disconnected_errors", 1);
return Err(P2PStreamError::HandshakeError(P2PHandshakeError::Disconnected(reason)))
}
id => {