use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub struct ActiveAlert {
pub rule_name: String,
pub triggered_at: SystemTime,
pub current_value: f64,
pub threshold: f64,
pub status: AlertStatus,
}
#[derive(Debug, Clone)]
pub enum AlertStatus {
Active,
Resolved,
Suppressed,
}
#[derive(Debug, Clone)]
pub struct EscalationPolicy {
pub name: String,
pub escalation_levels: Vec<EscalationLevel>,
pub auto_resolution: bool,
}
#[derive(Debug, Clone)]
pub struct EscalationLevel {
pub delay: Duration,
pub actions: Vec<AlertAction>,
pub conditions: Vec<EscalationCondition>,
}
#[derive(Debug, Clone)]
pub enum EscalationCondition {
TimeElapsed(Duration),
ValueStillAbove(f64),
MultipleFailures(usize),
}
#[derive(Debug, Clone)]
pub struct DashboardMetrics {
pub time_series: HashMap<String, TimeSeries>,
pub histograms: HashMap<String, Histogram>,
pub counters: HashMap<String, Counter>,
pub gauges: HashMap<String, Gauge>,
}
#[derive(Debug, Clone)]
pub struct TimeSeries {
pub points: VecDeque<TimeSeriesPoint>,
pub retention_period: Duration,
pub aggregation_interval: Duration,
}
#[derive(Debug, Clone)]
pub struct TimeSeriesPoint {
pub timestamp: SystemTime,
pub value: f64,
pub tags: HashMap<String, String>,
}
#[derive(Debug, Clone)]
pub struct Histogram {
pub buckets: Vec<f64>,
pub counts: Vec<usize>,
pub sum: f64,
pub count: usize,
}
#[derive(Debug, Clone)]
pub struct Counter {
pub value: usize,
pub rate: f64,
pub labels: HashMap<String, String>,
}
#[derive(Debug, Clone)]
pub struct Gauge {
pub value: f64,
pub min_value: f64,
pub max_value: f64,
pub trend: Trend,
}
#[derive(Debug, Clone)]
pub enum Trend {
Increasing,
Decreasing,
Stable,
}
#[derive(Debug, Clone)]
pub struct StreamingAnalytics {
pub sliding_windows: HashMap<String, SlidingWindow>,
pub tumbling_windows: HashMap<String, TumblingWindow>,
pub session_windows: HashMap<String, SessionWindow>,
}
#[derive(Debug, Clone)]
pub struct SlidingWindow {
pub window_size: Duration,
pub slide_interval: Duration,
pub aggregation_function: AggregationFunction,
pub current_value: f64,
}
#[derive(Debug, Clone)]
pub struct TumblingWindow {
pub window_size: Duration,
pub aggregation_function: AggregationFunction,
pub windows: VecDeque<WindowResult>,
}
#[derive(Debug, Clone)]
pub struct SessionWindow {
pub session_timeout: Duration,
pub aggregation_function: AggregationFunction,
pub active_sessions: HashMap<String, SessionData>,
}
#[derive(Debug, Clone)]
pub struct SessionData {
pub session_id: String,
pub start_time: SystemTime,
pub last_activity: SystemTime,
pub events: Vec<SessionEvent>,
}
#[derive(Debug, Clone)]
pub struct SessionEvent {
pub timestamp: SystemTime,
pub event_type: String,
pub value: f64,
}
#[derive(Debug, Clone)]
pub struct WindowResult {
pub start_time: SystemTime,
pub end_time: SystemTime,
pub value: f64,
pub count: usize,
}
#[derive(Debug, Clone)]
pub enum AggregationFunction {
Sum,
Average,
Min,
Max,
Count,
Median,
Percentile(f64),
StandardDeviation,
Variance,
}
#[derive(Debug, Clone)]
pub struct AnomalyDetector {
statistical_detector: StatisticalAnomalyDetector,
ml_detector: MlAnomalyDetector,
rule_based_detector: RuleBasedAnomalyDetector,
ensemble_detector: EnsembleAnomalyDetector,
}
#[derive(Debug, Clone)]
pub struct StatisticalAnomalyDetector {
pub z_score_threshold: f64,
pub iqr_multiplier: f64,
pub moving_average_window: usize,
pub seasonal_decomposition: bool,
}
#[derive(Debug, Clone)]
pub struct MlAnomalyDetector {
pub isolation_forest: IsolationForest,
pub one_class_svm: OneClassSvm,
pub autoencoder: Autoencoder,
pub lstm_detector: LstmDetector,
}
#[derive(Debug, Clone)]
pub struct IsolationForest {
pub num_trees: usize,
pub contamination_rate: f64,
pub trees: Vec<IsolationTree>,
}
#[derive(Debug, Clone)]
pub struct IsolationTree {
pub depth: usize,
pub splits: Vec<TreeSplit>,
}
#[derive(Debug, Clone)]
pub struct TreeSplit {
pub feature_index: usize,
pub split_value: f64,
pub left_child: Option<Box<TreeSplit>>,
pub right_child: Option<Box<TreeSplit>>,
}
#[derive(Debug, Clone)]
pub struct OneClassSvm {
pub nu: f64,
pub gamma: f64,
pub support_vectors: Vec<Vec<f64>>,
pub decision_function: Vec<f64>,
}
#[derive(Debug, Clone)]
pub struct Autoencoder {
pub encoder_layers: Vec<NeuralLayer>,
pub decoder_layers: Vec<NeuralLayer>,
pub reconstruction_threshold: f64,
}
#[derive(Debug, Clone)]
pub struct LstmDetector {
pub lstm_layers: Vec<LstmLayer>,
pub sequence_length: usize,
pub prediction_threshold: f64,
}
#[derive(Debug, Clone)]
pub struct LstmLayer {
pub hidden_size: usize,
pub cell_weights: Vec<Vec<f64>>,
pub hidden_weights: Vec<Vec<f64>>,
pub biases: Vec<f64>,
}
#[derive(Debug, Clone)]
pub struct RuleBasedAnomalyDetector {
pub rules: Vec<AnomalyRule>,
pub rule_priorities: HashMap<String, i32>,
}
#[derive(Debug, Clone)]
pub struct AnomalyRule {
pub name: String,
pub condition: AnomalyCondition,
pub severity: AnomalySeverity,
pub description: String,
}
#[derive(Debug, Clone)]
pub enum AnomalyCondition {
ThresholdExceeded { metric: String, threshold: f64 },
PatternDeviation { pattern: String, deviation: f64 },
SequentialFailures { count: usize, window: Duration },
ResourceExhaustion { resource: ResourceType, threshold: f64 },
}
#[derive(Debug, Clone)]
pub enum AnomalySeverity {
Low,
Medium,
impl DashboardMetrics {
pub fn new() -> Self {
Self {
time_series: HashMap::new(),
histograms: HashMap::new(),
counters: HashMap::new(),
gauges: HashMap::new(),
}
}
}
impl StreamingAnalytics {
pub fn new() -> Self {
Self {
sliding_windows: HashMap::new(),
tumbling_windows: HashMap::new(),
session_windows: HashMap::new(),
}
}
}