diff --git a/src/metrics/family.rs b/src/metrics/family.rs index 2f23b198..8f4f4721 100644 --- a/src/metrics/family.rs +++ b/src/metrics/family.rs @@ -288,6 +288,33 @@ impl> Family, Counter>::default(); + /// assert_eq!(family.len(), 0); + /// + /// // Will create the metric with label `method="GET"` on first call and + /// // return a reference. + /// family.get_or_create(&vec![("method".to_owned(), "GET".to_owned())]).inc(); + /// assert_eq!(family.len(), 1); + /// + /// // Clear the family of all label sets. + /// family.clear(); + /// assert_eq!(family.len(), 0); + /// ``` + pub fn len(&self) -> usize { + self.metrics.read().len() + } + + /// Returns `true` if the family contains no metrics. + pub fn is_empty(&self) -> bool { + self.metrics.read().is_empty() + } + pub(crate) fn read(&self) -> RwLockReadGuard> { self.metrics.read() }