5 个版本 (2 个稳定版)

1.0.1 2022年7月19日
1.0.0 2022年3月16日
0.2.0 2020年12月1日
0.1.1 2020年1月21日
0.1.0 2019年11月21日

#130性能分析 中排名

Download history 1950/week @ 2024-03-31 2120/week @ 2024-04-07 1346/week @ 2024-04-14 1420/week @ 2024-04-21 2025/week @ 2024-04-28 1731/week @ 2024-05-05 1600/week @ 2024-05-12 1620/week @ 2024-05-19 1333/week @ 2024-05-26 1730/week @ 2024-06-02 1776/week @ 2024-06-09 1486/week @ 2024-06-16 1189/week @ 2024-06-23 1599/week @ 2024-06-30 1351/week @ 2024-07-07 1440/week @ 2024-07-14

每月下载 5,800
4 个crate中 使用 (3 直接使用)

Apache-2.0

46KB
979 代码行

通用型指标库。

该crate的设计与Java生态系统的Dropwizard Metrics库的设计非常相似。

示例

use witchcraft_metrics::{MetricRegistry, MetricId, Metric};
use std::time::Duration;

// A `MetricRegistry` stores metrics.
let registry = MetricRegistry::new();

// Metrics are identified by an ID, which consists of a name and set of "tags"
let yaks_shaved = registry.counter(MetricId::new("shavings").with_tag("animal", "yak"));
// You can also pass a string directly for metric IDs that don't have tags
let request_timer = registry.timer("server.requests");

// do some work and record some values.
for yak in find_some_yaks() {
    shave_yak(yak);
    yaks_shaved.inc();
}

// Grab a snapshot of the metrics currently registered and print their values:
for (id, metric) in &registry.metrics() {
    match metric {
        Metric::Counter(counter) => println!("{:?} is a counter with value {}", id, counter.count()),
        Metric::Timer(timer) => {
            let nanos = timer.snapshot().value(0.99);
            let duration = Duration::from_nanos(nanos as u64);
            println!("{:?} is a timer with 99th percentile {:?}", id, duration);
        }
        _ => {}
    }
}

依赖关系

~1–6.5MB
~30K SLoC