Module prometheus_client::encoding::text

source ·
Expand description

Open Metrics text format implementation.

let mut buffer = String::new();

// Encode the complete OpenMetrics exposition into the message buffer
encode(&mut buffer, &registry).unwrap();
let expected_msg = "# 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_msg, buffer);
buffer.clear();

// Encode just the registry into the message buffer
encode_registry(&mut buffer, &registry).unwrap();
let expected_reg = "# HELP my_counter This is my counter.\n".to_owned() +
                   "# TYPE my_counter counter\n" +
                   "my_counter_total 1\n";
assert_eq!(expected_reg, buffer);

// Encode EOF marker into message buffer to complete the OpenMetrics exposition
encode_eof(&mut buffer).unwrap();
assert_eq!(expected_msg, buffer);

Functions§

  • Encode both the metrics registered with the provided Registry and the EOF marker into the provided Writer using the OpenMetrics text format.
  • Encode the EOF marker into the provided Writer using the OpenMetrics text format.
  • Encode the metrics registered with the provided Registry into the provided Writer using the OpenMetrics text format.