[][src]Macro metrics::register_counter

register_counter!() { /* proc-macro */ }

Registers a counter.

Counters represent a single monotonic value, which means the value can only be incremented, not decremented, and always starts out with an initial value of zero.

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

Example

// A basic counter:
register_counter!("some_metric_name");

// Providing a unit for a counter:
register_counter!("some_metric_name", Unit::Bytes);

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

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

// We can combine the units, description, and labels arbitrarily:
register_counter!("some_metric_name", Unit::Bytes, "total number of bytes");
register_counter!("some_metric_name", Unit::Bytes, "service" => "http");
register_counter!("some_metric_name", "total number of bytes", "service" => "http");

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

// We can also pass labels by giving a vector or slice of key/value pairs.  In this scenario,
// a unit or description can still be passed in their respective positions:
let dynamic_val = "woo";
let labels = [("dynamic_key", format!("{}!", dynamic_val))];
register_counter!("some_metric_name", &labels);