Skip to content

Commit

Permalink
Add a metric to track the number of managed files per column family i…
Browse files Browse the repository at this point in the history
…n RocksDb
  • Loading branch information
halfprice committed Sep 4, 2024
1 parent aa9dd42 commit a7f4359
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions crates/typed-store/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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).",
Expand Down
14 changes: 13 additions & 1 deletion crates/typed-store/src/rocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -902,7 +903,7 @@ impl<K, V> DBMap<K, V> {
fn get_int_property(
rocksdb: &RocksDB,
cf: &impl AsColumnFamilyRef,
property_name: &'static std::ffi::CStr,
property_name: &std::ffi::CStr,
) -> Result<i64, TypedStoreError> {
match rocksdb.property_int_value_cf(cf, property_name) {
Ok(Some(value)) => Ok(value.try_into().unwrap()),
Expand Down Expand Up @@ -983,6 +984,17 @@ impl<K, V> DBMap<K, V> {
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
Expand Down

0 comments on commit a7f4359

Please sign in to comment.