Crates.io | metrics-prometheus-client |
lib.rs | metrics-prometheus-client |
version | 0.0.1 |
source | src |
created_at | 2024-07-21 09:05:47.013207 |
updated_at | 2024-07-21 09:05:47.013207 |
description | Creating compatibility between `metrics` and `prometheus_client`. |
homepage | https://github.com/paberr/metrics-prometheus-client |
repository | https://github.com/paberr/metrics-prometheus-client |
max_upload_size | |
id | 1310185 |
size | 23,300 |
Creating compatibility between metrics
and prometheus_client
.
use metrics_prometheus_client::install;
use prometheus_client::{encoding::text::encode, registry::Registry};
let collector = install();
// Use `metrics` crate interfaces.
metrics::counter!("count", "whose" => "mine", "kind" => "owned").increment(1);
let mut registry = Registry::default();
registry.register_collector(Box::new(collector));
let mut report = String::new();
encode(&mut report, ®istry).unwrap();
assert_eq!(
report.trim(),
"# HELP count \n# TYPE count counter\ncount_total{whose=\"mine\",kind=\"owned\"} 1\n# EOF"
.trim(),
);