Macro metrics::increment_gauge
source · [−]increment_gauge!() { /* proc-macro */ }
Expand description
Increments a gauge.
Gauges represent a single value that can go up or down over time, and always starts out with an initial value of zero.
Metric names are shown below using string literals, but they can also be owned String
values,
which includes using macros such as format!
directly at the callsite. String literals are
preferred for performance where possible.
Example
// A basic gauge:
increment_gauge!("some_metric_name", 42.2222);
// Specifying labels inline, including using constants for either the key or value:
increment_gauge!("some_metric_name", 66.6666, "service" => "http");
const SERVICE_LABEL: &'static str = "service";
const SERVICE_HTTP: &'static str = "http";
increment_gauge!("some_metric_name", 66.6666, SERVICE_LABEL => SERVICE_HTTP);
// We can also pass labels by giving a vector or slice of key/value pairs:
let dynamic_val = "woo";
let labels = [("dynamic_key", format!("{}!", dynamic_val))];
increment_gauge!("some_metric_name", 42.42, &labels);
// As mentioned in the documentation, metric names also can be owned strings, including ones
// generated at the callsite via things like `format!`:
let name = String::from("some_owned_metric_name");
increment_gauge!(name, 800.85);
increment_gauge!(format!("{}_via_format", "name"), 3.14);