[][src]Macro metrics::register_counter

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

Registers a counter.

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

Metrics can be registered with an optional description. Whether or not the installed recorder does anything with the description is implementation defined. Labels can also be specified when registering a metric.

Counters, when registered, start at 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:
register_counter!("some_metric_name");

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

// Providing a description for a counter:
register_counter!("some_metric_name", "number of woopsy daisies");

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

// And all combined:
register_counter!("some_metric_name", "number of woopsy daisies", "service" => "http");
register_counter!(<"some_metric_name">, "number of woopsy daisies", "service" => "http");

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