[][src]Macro stats::define_stats

macro_rules! define_stats {
    ($( $name:ident: $stat_type:tt($( $params:tt )*), )*) => { ... };
    (prefix = $prefix:expr;
     $( $name:ident: $stat_type:tt($( $params:tt )*), )*) => { ... };
}

The macro to define STATS module that contains static variables, one per counter you want to export. This is the main and recomended way to interact with statistics provided by this crate. If non empty prefix is passed then the exported counter name will be "{prefix}.{name}"

Examples:

use stats::prelude::*;
use fbinit::FacebookInit;

define_stats! {
    prefix = "my.test.counters";
    manual_c: singleton_counter(),
    test_c: counter(),
    test_c2: counter("test_c.two"),
    test_t: timeseries(Sum, Average),
    test_t2: timeseries("test_t.two"; Sum, Average),
    test_h: histogram(1, 0, 1000, Sum; P 99; P 50),
    dtest_c: dynamic_counter("test_c.{}", (job: u64)),
    dtest_t: dynamic_timeseries("test_t.{}", (region: &'static str); Rate, Sum),
    dtest_t2: dynamic_timeseries("test_t.two.{}.{}", (job: u64, region: &'static str); Count),
    dtest_h: dynamic_histogram("test_h.{}", (region: &'static str); 1, 0, 1000, Sum; P 99),
}

#[allow(non_snake_case)]
mod ALT_STATS {
    use stats::define_stats;
    define_stats! {
        test_t: timeseries(Sum, Average),
        test_t2: timeseries("test.two"; Sum, Average),
    }
    pub use self::STATS::*;
}

#[fbinit::main]
fn main(fb: FacebookInit) {
    STATS::manual_c.set_value(fb, 1);
    STATS::test_c.increment_value(1);
    STATS::test_c2.increment_value(100);
    STATS::test_t.add_value(1);
    STATS::test_t2.add_value_aggregated(79, 10);  // Add 79 and note it came from 10 samples
    STATS::test_h.add_value(1);
    STATS::test_h.add_repeated_value(1, 44);  // 44 times repeat adding 1
    STATS::dtest_c.increment_value(7, (1000,));
    STATS::dtest_t.add_value(77, ("lla",));
    STATS::dtest_t2.add_value_aggregated(81, 12, (7, "lla"));
    STATS::dtest_h.add_value(2, ("frc",));

    ALT_STATS::test_t.add_value(1);
    ALT_STATS::test_t2.add_value(1);
}