Skip to content

Commit

Permalink
Make stats in EvictingMap more useful
Browse files Browse the repository at this point in the history
Changes some of the stats published in prometheus in EvictingMap
to be more useful.
  • Loading branch information
allada committed Sep 9, 2023
1 parent 3c30387 commit 03c1a07
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions util/evicting_map.rs
Expand Up @@ -385,18 +385,19 @@ impl<T: LenEntry + Debug, I: InstantWrapper> MetricsComponent for EvictingMap<T,
&state
.lru
.peek_lru()
.map(|(_, v)| v.seconds_since_anchor as i64 + self.anchor_time.unix_timestamp() as i64)
.map(|(_, v)| self.anchor_time.unix_timestamp() as i64 - v.seconds_since_anchor as i64)
.unwrap_or(-1),
"Timestamp of the oldest item in the store",
);
c.publish(
"oldest_item_age_nanos",
"newest_item_timestamp",
&state
.lru
.peek_lru()
.map(|(_, v)| v.seconds_since_anchor as i64 + self.anchor_time.elapsed().as_secs() as i64)
.iter()
.next()
.map(|(_, v)| self.anchor_time.unix_timestamp() as i64 - v.seconds_since_anchor as i64)
.unwrap_or(-1),
"Age of the oldest item in the store in seconds",
"Timestamp of the newest item in the store",
);
c.publish(
"evicted_items_total",
Expand Down Expand Up @@ -435,8 +436,8 @@ impl<T: LenEntry + Debug, I: InstantWrapper> MetricsComponent for EvictingMap<T,
);
c.publish_stats(
"item_size_bytes",
state.lru.iter().take(10_000).map(|(_, v)| v.data.len()),
"Stats about the first 10_000 items in the store (these are oldest items in the store)",
state.lru.iter().take(1_000_000).map(|(_, v)| v.data.len()),
"Stats about the first 1_000_000 items in the store (these are newest items in the store)",
);
});
}
Expand Down

0 comments on commit 03c1a07

Please sign in to comment.