14 个版本

使用旧的 Rust 2015

0.1.13 2020年4月18日
0.1.12 2019年8月18日
0.1.11 2018年4月30日
0.1.10 2018年3月23日
0.1.2 2017年10月22日

#179值格式化

Download history 80/week @ 2024-04-07 115/week @ 2024-04-14 123/week @ 2024-04-21 132/week @ 2024-04-28 103/week @ 2024-05-05 108/week @ 2024-05-12 121/week @ 2024-05-19 126/week @ 2024-05-26 116/week @ 2024-06-02 99/week @ 2024-06-09 201/week @ 2024-06-16 126/week @ 2024-06-23 40/week @ 2024-06-30 86/week @ 2024-07-07 110/week @ 2024-07-14 98/week @ 2024-07-21

340 每月下载次数
用于 25 个 Crates (14 个直接)

MIT 许可证

100KB
2.5K SLoC

prometrics

Documentation Build Status Code Coverage License: MIT

Rust 暴露 Prometheus 度量的客户端库。

文档

示例

use prometrics::default_gatherer;
use prometrics::metrics::{CounterBuilder, GaugeBuilder};

let counter = CounterBuilder::new("count")
    .default_registry()
    .finish()
    .unwrap();
let gauge = GaugeBuilder::new("gauge")
    .label("foo", "bar")
    .default_registry()
    .finish()
    .unwrap();

 counter.increment();
 gauge.set(12.3);

 let metrics = default_gatherer().lock().unwrap().gather();
 assert_eq!(
    metrics.to_text(),
    format!("{}\n{}\n{}\n{}\n",
            "# TYPE count counter",
            "count 1",
            "# TYPE gauge gauge",
            "gauge{foo=\"bar\"} 12.3"));

基准测试

$ uname -a
Linux DESKTOP 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux

$ lscpu | grep 'Model name:'
Model name:            Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz

$ cargo +nightly bench
test counter_add_float       ... bench:          10 ns/iter (+/- 0)
test counter_add_round_float ... bench:           4 ns/iter (+/- 0)
test counter_add_u64         ... bench:           4 ns/iter (+/- 0)
test counter_increment       ... bench:           4 ns/iter (+/- 0)
test gauge_set               ... bench:           4 ns/iter (+/- 0)
test histogram_observe       ... bench:          18 ns/iter (+/- 0)
test summary_observe         ... bench:         481 ns/iter (+/- 21)

test result: ok. 0 passed; 0 failed; 0 ignored; 7 measured; 0 filtered out

参考文献

依赖项

~1.2–1.7MB
~39K SLoC