42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
//! Traits communs pour l'uniformisation des métriques.
|
|
|
|
use std::sync::Arc;
|
|
use std::time::Instant;
|
|
|
|
use crate::http::metrics::HttpMetrics;
|
|
use crate::udp::metrics::UdpMetrics;
|
|
|
|
/// Contrat minimal pour un jeu de compteurs métriques.
|
|
pub trait Metrics {
|
|
type Snapshot: MetricsSnapshot;
|
|
|
|
/// Prend un instantané cohérent des compteurs à l'instant T.
|
|
fn snapshot(&self) -> Self::Snapshot;
|
|
}
|
|
|
|
/// Contrat minimal pour un snapshot de métriques.
|
|
pub trait MetricsSnapshot: Clone {
|
|
/// Instant auquel le snapshot a été pris.
|
|
fn taken_at(&self) -> Instant;
|
|
}
|
|
|
|
// ── AppMetrics ────────────────────────────────────────────────────────────────
|
|
|
|
/// Regroupe toutes les métriques de l'application.
|
|
#[derive(Debug, Clone)]
|
|
pub struct AppMetrics {
|
|
pub http: Arc<HttpMetrics>,
|
|
pub udp: Arc<UdpMetrics>,
|
|
}
|
|
|
|
impl AppMetrics {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
http: HttpMetrics::new(),
|
|
udp: UdpMetrics::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub mod reporter;
|