Add more store metrics
This commit is contained in:
parent
913ee4694e
commit
0b4a8893a4
@ -1,4 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::metrics;
|
||||||
use db_key::Key;
|
use db_key::Key;
|
||||||
use leveldb::database::kv::KV;
|
use leveldb::database::kv::KV;
|
||||||
use leveldb::database::Database;
|
use leveldb::database::Database;
|
||||||
@ -62,15 +63,27 @@ impl Store for LevelDB {
|
|||||||
fn get_bytes(&self, col: &str, key: &[u8]) -> Result<Option<Vec<u8>>, Error> {
|
fn get_bytes(&self, col: &str, key: &[u8]) -> Result<Option<Vec<u8>>, Error> {
|
||||||
let column_key = Self::get_key_for_col(col, key);
|
let column_key = Self::get_key_for_col(col, key);
|
||||||
|
|
||||||
self.db
|
metrics::inc_counter(&metrics::DISK_DB_READ_COUNT);
|
||||||
|
|
||||||
|
let result = self
|
||||||
|
.db
|
||||||
.get(self.read_options(), column_key)
|
.get(self.read_options(), column_key)
|
||||||
.map_err(Into::into)
|
.map_err(Into::into);
|
||||||
|
|
||||||
|
if let Ok(Some(bytes)) = &result {
|
||||||
|
metrics::inc_counter_by(&metrics::DISK_DB_READ_BYTES, bytes.len() as i64)
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Store some `value` in `column`, indexed with `key`.
|
/// Store some `value` in `column`, indexed with `key`.
|
||||||
fn put_bytes(&self, col: &str, key: &[u8], val: &[u8]) -> Result<(), Error> {
|
fn put_bytes(&self, col: &str, key: &[u8], val: &[u8]) -> Result<(), Error> {
|
||||||
let column_key = Self::get_key_for_col(col, key);
|
let column_key = Self::get_key_for_col(col, key);
|
||||||
|
|
||||||
|
metrics::inc_counter(&metrics::DISK_DB_WRITE_COUNT);
|
||||||
|
metrics::inc_counter_by(&metrics::DISK_DB_WRITE_BYTES, val.len() as i64);
|
||||||
|
|
||||||
self.db
|
self.db
|
||||||
.put(self.write_options(), column_key, val)
|
.put(self.write_options(), column_key, val)
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
@ -80,6 +93,8 @@ impl Store for LevelDB {
|
|||||||
fn key_exists(&self, col: &str, key: &[u8]) -> Result<bool, Error> {
|
fn key_exists(&self, col: &str, key: &[u8]) -> Result<bool, Error> {
|
||||||
let column_key = Self::get_key_for_col(col, key);
|
let column_key = Self::get_key_for_col(col, key);
|
||||||
|
|
||||||
|
metrics::inc_counter(&metrics::DISK_DB_EXISTS_COUNT);
|
||||||
|
|
||||||
self.db
|
self.db
|
||||||
.get(self.read_options(), column_key)
|
.get(self.read_options(), column_key)
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
@ -89,6 +104,9 @@ impl Store for LevelDB {
|
|||||||
/// Removes `key` from `column`.
|
/// Removes `key` from `column`.
|
||||||
fn key_delete(&self, col: &str, key: &[u8]) -> Result<(), Error> {
|
fn key_delete(&self, col: &str, key: &[u8]) -> Result<(), Error> {
|
||||||
let column_key = Self::get_key_for_col(col, key);
|
let column_key = Self::get_key_for_col(col, key);
|
||||||
|
|
||||||
|
metrics::inc_counter(&metrics::DISK_DB_DELETE_COUNT);
|
||||||
|
|
||||||
self.db
|
self.db
|
||||||
.delete(self.write_options(), column_key)
|
.delete(self.write_options(), column_key)
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
|
@ -5,7 +5,31 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref DISK_DB_SIZE: Result<IntGauge> =
|
pub static ref DISK_DB_SIZE: Result<IntGauge> =
|
||||||
try_create_int_gauge("database_size", "Size of the on-disk database (bytes)");
|
try_create_int_gauge("store_disk_db_size", "Size of the on-disk database (bytes)");
|
||||||
|
pub static ref DISK_DB_WRITE_BYTES: Result<IntCounter> = try_create_int_counter(
|
||||||
|
"store_disk_db_write_bytes",
|
||||||
|
"Number of bytes attempted to be written to the on-disk DB"
|
||||||
|
);
|
||||||
|
pub static ref DISK_DB_READ_BYTES: Result<IntCounter> = try_create_int_counter(
|
||||||
|
"store_disk_db_read_bytes",
|
||||||
|
"Number of bytes read from the on-disk DB"
|
||||||
|
);
|
||||||
|
pub static ref DISK_DB_READ_COUNT: Result<IntCounter> = try_create_int_counter(
|
||||||
|
"store_disk_db_read_count",
|
||||||
|
"Total number of reads to the on-disk DB"
|
||||||
|
);
|
||||||
|
pub static ref DISK_DB_WRITE_COUNT: Result<IntCounter> = try_create_int_counter(
|
||||||
|
"store_disk_db_write_count",
|
||||||
|
"Total number of writes to the on-disk DB"
|
||||||
|
);
|
||||||
|
pub static ref DISK_DB_EXISTS_COUNT: Result<IntCounter> = try_create_int_counter(
|
||||||
|
"store_disk_db_exists_count",
|
||||||
|
"Total number of checks if a key is in the on-disk DB"
|
||||||
|
);
|
||||||
|
pub static ref DISK_DB_DELETE_COUNT: Result<IntCounter> = try_create_int_counter(
|
||||||
|
"store_disk_db_delete_count",
|
||||||
|
"Total number of deletions from the on-disk DB"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the global metrics registry with store-related information.
|
/// Updates the global metrics registry with store-related information.
|
||||||
|
@ -41,6 +41,12 @@ pub fn inc_counter(counter: &Result<IntCounter>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn inc_counter_by(counter: &Result<IntCounter>, value: i64) {
|
||||||
|
if let Ok(counter) = counter {
|
||||||
|
counter.inc_by(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_gauge(gauge: &Result<IntGauge>, value: i64) {
|
pub fn set_gauge(gauge: &Result<IntGauge>, value: i64) {
|
||||||
if let Ok(gauge) = gauge {
|
if let Ok(gauge) = gauge {
|
||||||
gauge.set(value);
|
gauge.set(value);
|
||||||
|
Loading…
Reference in New Issue
Block a user