kumo_prometheus/counter_bundle.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/// counter_bundle declares a struct holding a bundle of counters
/// that should be incremented or decremented together. This
/// is used to facilitate computing rolled up metrics.
#[macro_export]
macro_rules! counter_bundle {
(pub struct $name:ident {
$(
pub $fieldname:ident: AtomicCounter,
)*
}
) => {
#[derive(Clone)]
pub struct $name {
$(
pub $fieldname: AtomicCounter,
)*
}
impl $name {
pub fn inc(&self) {
$(
self.$fieldname.inc();
)*
}
pub fn dec(&self) {
$(
self.$fieldname.dec();
)*
}
pub fn sub(&self, n: usize) {
$(
self.$fieldname.sub(n);
)*
}
pub fn inc_by(&self, n: usize) {
$(
self.$fieldname.inc_by(n);
)*
}
}
};
}