diff --git a/crates/typed-store/src/metrics.rs b/crates/typed-store/src/metrics.rs index f7049d8d63768..826f9a3f46e29 100644 --- a/crates/typed-store/src/metrics.rs +++ b/crates/typed-store/src/metrics.rs @@ -77,6 +77,7 @@ impl SamplingInterval { pub struct ColumnFamilyMetrics { pub rocksdb_total_sst_files_size: IntGaugeVec, pub rocksdb_total_blob_files_size: IntGaugeVec, + pub rocksdb_total_num_files: IntGaugeVec, pub rocksdb_current_size_active_mem_tables: IntGaugeVec, pub rocksdb_size_all_mem_tables: IntGaugeVec, pub rocksdb_num_snapshots: IntGaugeVec, @@ -116,6 +117,13 @@ impl ColumnFamilyMetrics { registry, ) .unwrap(), + rocksdb_total_num_files: register_int_gauge_vec_with_registry!( + "rocksdb_total_num_files", + "Total number of files used in the column family", + &["cf_name"], + registry, + ) + .unwrap(), rocksdb_current_size_active_mem_tables: register_int_gauge_vec_with_registry!( "rocksdb_current_size_active_mem_tables", "The current approximate size of active memtable (bytes).", diff --git a/crates/typed-store/src/rocks/mod.rs b/crates/typed-store/src/rocks/mod.rs index 6bf550f4aa131..d24c227c2d084 100644 --- a/crates/typed-store/src/rocks/mod.rs +++ b/crates/typed-store/src/rocks/mod.rs @@ -21,6 +21,7 @@ use bincode::Options; use collectable::TryExtend; use itertools::Itertools; use prometheus::{Histogram, HistogramTimer}; +use rocksdb::properties::num_files_at_level; use rocksdb::{ checkpoint::Checkpoint, BlockBasedOptions, BottommostLevelCompaction, Cache, CompactOptions, DBPinnableSlice, LiveFile, OptimisticTransactionDB, SnapshotWithThreadMode, @@ -902,7 +903,7 @@ impl DBMap { fn get_int_property( rocksdb: &RocksDB, cf: &impl AsColumnFamilyRef, - property_name: &'static std::ffi::CStr, + property_name: &std::ffi::CStr, ) -> Result { match rocksdb.property_int_value_cf(cf, property_name) { Ok(Some(value)) => Ok(value.try_into().unwrap()), @@ -983,6 +984,17 @@ impl DBMap { Self::get_int_property(rocksdb, &cf, ROCKSDB_PROPERTY_TOTAL_BLOB_FILES_SIZE) .unwrap_or(METRICS_ERROR), ); + let total_num_files: i64 = (0..=6) + .map(|level| { + Self::get_int_property(rocksdb, &cf, &num_files_at_level(level)) + .unwrap_or(METRICS_ERROR) + }) + .sum(); + db_metrics + .cf_metrics + .rocksdb_total_num_files + .with_label_values(&[cf_name]) + .set(total_num_files); db_metrics .cf_metrics .rocksdb_current_size_active_mem_tables