[][src]Crate open_metrics_client

Client library implementing the Open Metrics specification allowing users to natively instrument applications.

Examples

// Create registry and counter and register the latter with the former.
let mut registry = Registry::new();
let counter = Counter::<AtomicU64>::new();
registry.register(
  Descriptor::new("counter", "This is my counter.", "my_counter"),
  counter.clone(),
);

// Record an observation by increasing the counter.
counter.inc();

// Encode all metrics in the registry in the text format.
let mut buffer = vec![];
encode::<_, _>(&mut buffer, &registry).unwrap();

let expected = "# HELP my_counter This is my counter.\n".to_owned() +
               "# TYPE my_counter counter\n" +
               "my_counter_total 1\n" +
               "# EOF\n";
assert_eq!(expected, String::from_utf8(buffer).unwrap());

See examples directory for more.

Modules

counter
encoding
family
gauge
histogram
registry