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, ®istry).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, ®istry).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 the EOF marker into the provided
Write
r using the OpenMetrics text format.