mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-10 07:06:53 +00:00
refactor(metrics): separate console stream from exports (#2583)
This commit is contained in:
@@ -24,6 +24,10 @@ description = "Metrics collection and reporting for RustFS (using metrics crate
|
||||
keywords = ["metrics", "zero-copy", "rustfs", "otel", "performance"]
|
||||
categories = ["development-tools", "filesystem"]
|
||||
|
||||
[[bench]]
|
||||
name = "metrics_pipeline"
|
||||
harness = false
|
||||
|
||||
[dependencies]
|
||||
metrics = { workspace = true }
|
||||
num_cpus = { workspace = true }
|
||||
@@ -32,6 +36,7 @@ tokio = { workspace = true, features = ["sync","rt"] }
|
||||
tracing = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { workspace = true }
|
||||
tokio = { workspace = true, features = ["test-util","rt","macros"] }
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
- **Bandwidth Monitoring**: Real-time bandwidth observation and analysis
|
||||
- **Performance Metrics**: I/O performance metrics collection
|
||||
- **Unified Configuration**: Centralized configuration management
|
||||
- **Exporter Boundary**: Emit via `metrics`, export via `rustfs-obs`, no Prometheus HTTP endpoint
|
||||
|
||||
## Features
|
||||
|
||||
@@ -199,7 +200,7 @@ cargo test --package rustfs-io-metrics
|
||||
cargo test --package rustfs-io-metrics --lib adaptive_ttl
|
||||
|
||||
# Run benchmarks
|
||||
cargo bench --package rustfs-io-metrics
|
||||
cargo bench --package rustfs-io-metrics --bench metrics_pipeline
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
- **带宽监控**:实时带宽观测和分析
|
||||
- **性能指标**:I/O 性能指标收集
|
||||
- **统一配置**:集中式配置管理
|
||||
- **导出边界**:通过 `metrics` 主动上报,由 `rustfs-obs` 负责 OTEL 导出,不提供 Prometheus HTTP 端点
|
||||
|
||||
## ✨ 核心功能
|
||||
|
||||
@@ -280,7 +281,7 @@ cargo test --package rustfs-io-metrics
|
||||
cargo test --package rustfs-io-metrics --lib adaptive_ttl
|
||||
|
||||
# 运行基准测试
|
||||
cargo bench --package rustfs-io-metrics
|
||||
cargo bench --package rustfs-io-metrics --bench metrics_pipeline
|
||||
```
|
||||
|
||||
## 📚 文档
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
use criterion::{Criterion, criterion_group, criterion_main};
|
||||
use rustfs_io_metrics::{MetricsCollector, PerformanceMetrics, record_get_object_request_started};
|
||||
use std::hint::black_box;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
fn bench_record_get_object_request_started(c: &mut Criterion) {
|
||||
c.bench_function("record_get_object_request_started", |b| b.iter(record_get_object_request_started));
|
||||
}
|
||||
|
||||
fn bench_update_concurrent_requests(c: &mut Criterion) {
|
||||
let metrics = PerformanceMetrics::new();
|
||||
|
||||
c.bench_function("performance_metrics_update_concurrent_requests", |b| {
|
||||
b.iter(|| metrics.update_concurrent_requests(black_box(64)))
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_metrics_collector_record_io_operation(c: &mut Criterion) {
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.expect("build tokio runtime for io-metrics benchmark");
|
||||
let collector = MetricsCollector::new(Arc::new(PerformanceMetrics::new()), 256);
|
||||
|
||||
c.bench_function("metrics_collector_record_io_operation", |b| {
|
||||
b.iter(|| {
|
||||
runtime.block_on(collector.record_io_operation(
|
||||
black_box(64 * 1024),
|
||||
Duration::from_micros(black_box(250)),
|
||||
black_box(true),
|
||||
))
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
bench_record_get_object_request_started,
|
||||
bench_update_concurrent_requests,
|
||||
bench_metrics_collector_record_io_operation
|
||||
);
|
||||
criterion_main!(benches);
|
||||
@@ -143,7 +143,7 @@ fn metrics_recording_example() {
|
||||
|
||||
println!(" Recorded 10 cache operations (hits: 7, misses: 3)");
|
||||
println!(" Metrics reported via metrics crate");
|
||||
println!(" View via Prometheus/Grafana");
|
||||
println!(" Export via rustfs-obs OTEL pipeline");
|
||||
|
||||
println!();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
//! - **PerformanceMetrics**: Shared atomic counter struct for advanced use cases
|
||||
//! - **MetricsCollector**: I/O operation tracking with percentile calculation
|
||||
//! - **AutoTuner**: Automatic performance optimization based on metrics
|
||||
//! - **No HTTP metrics endpoint**: consumers emit metrics through the `metrics` crate;
|
||||
//! `rustfs-obs` owns OTEL initialization and export
|
||||
//!
|
||||
//! # Usage
|
||||
//!
|
||||
|
||||
Reference in New Issue
Block a user