use std::sync::atomic::{AtomicU64, Ordering};
#[derive(Default, Debug)]
pub struct SubsystemMetrics {
pub embedding_requests_total: AtomicU64,
pub embedding_fallbacks_total: AtomicU64,
pub consolidation_runs_total: AtomicU64,
pub consolidation_pruned_total: AtomicU64,
pub consolidation_promoted_total: AtomicU64,
pub circuit_open_total: AtomicU64,
pub circuit_resets_total: AtomicU64,
pub intent_classifications_total: AtomicU64,
pub intent_llm_fallbacks_total: AtomicU64,
}
impl SubsystemMetrics {
pub fn new() -> Self {
Self::default()
}
#[inline]
pub fn inc_embedding_request(&self) {
self.embedding_requests_total
.fetch_add(1, Ordering::Relaxed);
}
#[inline]
pub fn inc_embedding_fallback(&self) {
self.embedding_fallbacks_total
.fetch_add(1, Ordering::Relaxed);
}
#[inline]
pub fn inc_consolidation_run(&self) {
self.consolidation_runs_total
.fetch_add(1, Ordering::Relaxed);
}
#[inline]
pub fn add_consolidation_pruned(&self, n: u64) {
self.consolidation_pruned_total
.fetch_add(n, Ordering::Relaxed);
}
#[inline]
pub fn add_consolidation_promoted(&self, n: u64) {
self.consolidation_promoted_total
.fetch_add(n, Ordering::Relaxed);
}
#[inline]
pub fn inc_circuit_open(&self) {
self.circuit_open_total.fetch_add(1, Ordering::Relaxed);
}
#[inline]
pub fn inc_circuit_reset(&self) {
self.circuit_resets_total.fetch_add(1, Ordering::Relaxed);
}
#[inline]
pub fn inc_intent_classification(&self) {
self.intent_classifications_total
.fetch_add(1, Ordering::Relaxed);
}
#[inline]
pub fn inc_intent_llm_fallback(&self) {
self.intent_llm_fallbacks_total
.fetch_add(1, Ordering::Relaxed);
}
pub fn snapshot(&self) -> SubsystemSnapshot {
SubsystemSnapshot {
embedding_requests_total: self.embedding_requests_total.load(Ordering::Relaxed),
embedding_fallbacks_total: self.embedding_fallbacks_total.load(Ordering::Relaxed),
consolidation_runs_total: self.consolidation_runs_total.load(Ordering::Relaxed),
consolidation_pruned_total: self.consolidation_pruned_total.load(Ordering::Relaxed),
consolidation_promoted_total: self.consolidation_promoted_total.load(Ordering::Relaxed),
circuit_open_total: self.circuit_open_total.load(Ordering::Relaxed),
circuit_resets_total: self.circuit_resets_total.load(Ordering::Relaxed),
intent_classifications_total: self.intent_classifications_total.load(Ordering::Relaxed),
intent_llm_fallbacks_total: self.intent_llm_fallbacks_total.load(Ordering::Relaxed),
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct SubsystemSnapshot {
pub embedding_requests_total: u64,
pub embedding_fallbacks_total: u64,
pub consolidation_runs_total: u64,
pub consolidation_pruned_total: u64,
pub consolidation_promoted_total: u64,
pub circuit_open_total: u64,
pub circuit_resets_total: u64,
pub intent_classifications_total: u64,
pub intent_llm_fallbacks_total: u64,
}