[][src]Macro metrics::counter

macro_rules! counter {
    #[proc_macro_hack] => { ... };
}

Increments a counter.

Counters represent a single value that can only be incremented over time, or reset to zero.

Scoped versus unscoped

Metrics can be unscoped or scoped, where the scoping is derived by the current module the call is taking place in. This scope is used as a prefix to the provided metric name.

Example

// A regular, unscoped counter:
counter!("some_metric_name", 12);

// A scoped counter.  This inherits a scope derived by the current module:
counter!(<"some_metric_name">, 12);

// Specifying labels:
counter!("some_metric_name", 12, "service" => "http");

// And all combined:
counter!("some_metric_name", 12, "service" => "http");
counter!(<"some_metric_name">, 12, "service" => "http");

// And just for an alternative form of passing labels:
let dynamic_val = "woo";
let labels = [("dynamic_key", format!("{}!", dynamic_val))];
counter!("some_metric_name", 12, &labels);