feat(rpc): track cache hits and misses (#5094)

This commit is contained in:
Roman Krasiuk
2023-10-19 06:24:58 -07:00
committed by GitHub
parent 2f66662f62
commit 78f666e62e
2 changed files with 12 additions and 1 deletions

View File

@ -1,3 +1,4 @@
use metrics::Counter;
use reth_metrics::{metrics::Gauge, Metrics};
#[derive(Metrics)]
@ -7,4 +8,8 @@ pub(crate) struct CacheMetrics {
pub(crate) cached_count: Gauge,
/// The number of queued consumers.
pub(crate) queued_consumers_count: Gauge,
/// The number of cache hits.
pub(crate) hits: Counter,
/// The number of cache misses.
pub(crate) misses: Counter,
}

View File

@ -70,7 +70,13 @@ where
/// Returns a reference to the value for a given key and promotes that element to be the most
/// recently used.
pub fn get(&mut self, key: &K) -> Option<&mut V> {
self.cache.get(key)
let entry = self.cache.get(key);
if entry.is_some() {
self.metrics.hits.increment(1);
} else {
self.metrics.misses.increment(1);
}
entry
}
/// Inserts a new element into the map.