mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-19 03:04:27 -05:00
feat(grafana): add RocksDB metrics dashboard (#21243)
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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!(
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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
Reference in New Issue
Block a user