feat(grafana): add RocksDB metrics dashboard (#21243)

Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
joshieDo
2026-01-21 22:09:42 +00:00
committed by GitHub
parent 72e1467ba3
commit eb55c3c3da
6 changed files with 845 additions and 80 deletions

View File

@@ -1277,6 +1277,10 @@ pub fn metrics_hooks<N: NodeTypesWithDB>(provider_factory: &ProviderFactory<N>)
})
}
})
.with_hook({
let rocksdb = provider_factory.rocksdb_provider();
move || throttle!(Duration::from_secs(5 * 60), || rocksdb.report_metrics())
})
.build()
}

View File

@@ -106,6 +106,7 @@ impl MetricServer {
// Describe metrics after recorder installation
describe_db_metrics();
describe_static_file_metrics();
describe_rocksdb_metrics();
Collector::default().describe();
describe_memory_stats();
describe_io_stats();
@@ -238,6 +239,26 @@ fn describe_static_file_metrics() {
);
}
fn describe_rocksdb_metrics() {
describe_gauge!(
"rocksdb.table_size",
Unit::Bytes,
"The estimated size of a RocksDB table (SST + memtable)"
);
describe_gauge!("rocksdb.table_entries", "The estimated number of keys in a RocksDB table");
describe_gauge!(
"rocksdb.pending_compaction_bytes",
Unit::Bytes,
"Bytes pending compaction for a RocksDB table"
);
describe_gauge!("rocksdb.sst_size", Unit::Bytes, "The size of SST files for a RocksDB table");
describe_gauge!(
"rocksdb.memtable_size",
Unit::Bytes,
"The size of memtables for a RocksDB table"
);
}
#[cfg(all(feature = "jemalloc", unix))]
fn describe_memory_stats() {
describe_gauge!(

View File

@@ -85,7 +85,7 @@ rand.workspace = true
tokio = { workspace = true, features = ["sync", "macros", "rt-multi-thread"] }
[features]
edge = ["reth-storage-api/edge"]
edge = ["reth-storage-api/edge", "rocksdb"]
rocksdb = ["dep:rocksdb"]
test-utils = [
"reth-db/test-utils",

View File

@@ -3,9 +3,11 @@ use crate::providers::{compute_history_rank, needs_prev_shard_check, HistoryInfo
use alloy_consensus::transaction::TxHashRef;
use alloy_primitives::{Address, BlockNumber, TxNumber, B256};
use itertools::Itertools;
use metrics::Label;
use parking_lot::Mutex;
use reth_chain_state::ExecutedBlock;
use reth_db_api::{
database_metrics::DatabaseMetrics,
models::{
sharded_key::NUM_OF_INDICES_IN_SHARD, storage_sharded_key::StorageShardedKey, ShardedKey,
StorageSettings,
@@ -529,6 +531,42 @@ impl Clone for RocksDBProvider {
}
}
impl DatabaseMetrics for RocksDBProvider {
fn gauge_metrics(&self) -> Vec<(&'static str, f64, Vec<Label>)> {
let mut metrics = Vec::new();
for stat in self.table_stats() {
metrics.push((
"rocksdb.table_size",
stat.estimated_size_bytes as f64,
vec![Label::new("table", stat.name.clone())],
));
metrics.push((
"rocksdb.table_entries",
stat.estimated_num_keys as f64,
vec![Label::new("table", stat.name.clone())],
));
metrics.push((
"rocksdb.pending_compaction_bytes",
stat.pending_compaction_bytes as f64,
vec![Label::new("table", stat.name.clone())],
));
metrics.push((
"rocksdb.sst_size",
stat.sst_size_bytes as f64,
vec![Label::new("table", stat.name.clone())],
));
metrics.push((
"rocksdb.memtable_size",
stat.memtable_size_bytes as f64,
vec![Label::new("table", stat.name)],
));
}
metrics
}
}
impl RocksDBProvider {
/// Creates a new `RocksDB` provider.
pub fn new(path: impl AsRef<Path>) -> ProviderResult<Self> {

View File

@@ -5,8 +5,9 @@
//! All method calls are cfg-guarded in the calling code, so only type definitions are needed here.
use alloy_primitives::BlockNumber;
use metrics::Label;
use parking_lot::Mutex;
use reth_db_api::models::StorageSettings;
use reth_db_api::{database_metrics::DatabaseMetrics, models::StorageSettings};
use reth_prune_types::PruneMode;
use reth_storage_errors::{db::LogLevel, provider::ProviderResult};
use std::{path::Path, sync::Arc};
@@ -82,6 +83,12 @@ impl RocksDBProvider {
}
}
impl DatabaseMetrics for RocksDBProvider {
fn gauge_metrics(&self) -> Vec<(&'static str, f64, Vec<Label>)> {
vec![]
}
}
/// A stub batch writer for `RocksDB`.
#[derive(Debug)]
pub struct RocksDBBatch;

File diff suppressed because it is too large Load Diff