feat: move metrics to its own crate (#9691)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Luca Provini
2024-07-25 17:47:46 +02:00
committed by GitHub
parent abdbc44c9b
commit 93ebdf292b
24 changed files with 711 additions and 462 deletions

View File

@ -28,6 +28,7 @@ reth-network-p2p.workspace = true
reth-node-builder.workspace = true
reth-node-core.workspace = true
reth-node-events.workspace = true
reth-node-metrics.workspace = true
reth-primitives.workspace = true
reth-provider.workspace = true
reth-prune.workspace = true
@ -63,9 +64,6 @@ ratatui = { version = "0.27", default-features = false, features = [
"crossterm",
] }
# metrics
metrics-process.workspace = true
# reth test-vectors
proptest = { workspace = true, optional = true }
arbitrary = { workspace = true, optional = true }

View File

@ -15,6 +15,7 @@ use reth_node_core::{
node_config::NodeConfig,
version,
};
use reth_node_metrics::recorder::install_prometheus_recorder;
use std::{ffi::OsString, fmt, future::Future, net::SocketAddr, path::PathBuf, sync::Arc};
/// Start the node
@ -173,7 +174,7 @@ impl<Ext: clap::Args + fmt::Debug> NodeCommand<Ext> {
// Register the prometheus recorder before creating the database,
// because database init needs it to register metrics.
let _ = node_config.install_prometheus_recorder()?;
let _ = install_prometheus_recorder();
let data_dir = node_config.datadir();
let db_path = data_dir.db();

View File

@ -13,7 +13,15 @@ use reth_evm::execute::BlockExecutorProvider;
use reth_exex::ExExManagerHandle;
use reth_node_core::{
args::{NetworkArgs, StageEnum},
prometheus_exporter,
version::{
BUILD_PROFILE_NAME, CARGO_PKG_VERSION, VERGEN_BUILD_TIMESTAMP, VERGEN_CARGO_FEATURES,
VERGEN_CARGO_TARGET_TRIPLE, VERGEN_GIT_SHA,
},
};
use reth_node_metrics::{
hooks::Hooks,
server::{MetricServer, MetricServerConfig},
version::VersionInfo,
};
use reth_provider::{
ChainSpecProvider, StageCheckpointReader, StageCheckpointWriter, StaticFileProviderFactory,
@ -99,15 +107,24 @@ impl Command {
if let Some(listen_addr) = self.metrics {
info!(target: "reth::cli", "Starting metrics endpoint at {}", listen_addr);
prometheus_exporter::serve(
let config = MetricServerConfig::new(
listen_addr,
prometheus_exporter::install_recorder()?,
provider_factory.db_ref().clone(),
provider_factory.static_file_provider(),
metrics_process::Collector::default(),
VersionInfo {
version: CARGO_PKG_VERSION,
build_timestamp: VERGEN_BUILD_TIMESTAMP,
cargo_features: VERGEN_CARGO_FEATURES,
git_sha: VERGEN_GIT_SHA,
target_triple: VERGEN_CARGO_TARGET_TRIPLE,
build_profile: BUILD_PROFILE_NAME,
},
ctx.task_executor,
)
.await?;
Hooks::new(
provider_factory.db_ref().clone(),
provider_factory.static_file_provider(),
),
);
MetricServer::new(config).serve().await?;
}
let batch_size = self.batch_size.unwrap_or(self.to.saturating_sub(self.from) + 1);