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