quantrs2_device/cloud/monitoring/
performance.rs

1//! Performance monitoring configuration and metrics.
2
3use serde::{Deserialize, Serialize};
4use std::time::Duration;
5
6/// Performance monitoring configuration
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct CloudPerformanceMonitoringConfig {
9    /// Enable performance monitoring
10    pub enabled: bool,
11    /// Metrics to collect
12    pub metrics: Vec<PerformanceMetric>,
13    /// Collection frequency
14    pub frequency: Duration,
15    /// Data retention
16    pub retention: Duration,
17    /// Real-time monitoring
18    pub real_time: RealTimeMonitoringConfig,
19    /// Performance thresholds
20    pub thresholds: PerformanceThresholds,
21    /// Benchmarking configuration
22    pub benchmarking: BenchmarkingConfig,
23}
24
25/// Performance metrics
26#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
27pub enum PerformanceMetric {
28    Latency,
29    Throughput,
30    ResponseTime,
31    ErrorRate,
32    Availability,
33    CPUUtilization,
34    MemoryUtilization,
35    NetworkUtilization,
36    DiskUtilization,
37    QuantumCircuitDepth,
38    QuantumGateErrors,
39    QuantumCoherence,
40    Custom(String),
41}
42
43/// Real-time monitoring configuration
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct RealTimeMonitoringConfig {
46    /// Enable real-time monitoring
47    pub enabled: bool,
48    /// Streaming frequency
49    pub streaming_frequency: Duration,
50    /// Buffer size
51    pub buffer_size: usize,
52    /// Aggregation window
53    pub aggregation_window: Duration,
54    /// Real-time dashboards
55    pub dashboards: Vec<DashboardConfig>,
56}
57
58/// Performance threshold configuration
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct PerformanceThresholds {
61    /// Warning thresholds
62    pub warning: ThresholdLevels,
63    /// Critical thresholds
64    pub critical: ThresholdLevels,
65    /// Custom thresholds per metric
66    pub custom_thresholds: std::collections::HashMap<PerformanceMetric, ThresholdLevels>,
67}
68
69/// Threshold levels for performance metrics
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct ThresholdLevels {
72    /// CPU utilization threshold (percentage)
73    pub cpu_utilization: f64,
74    /// Memory utilization threshold (percentage)
75    pub memory_utilization: f64,
76    /// Network utilization threshold (percentage)
77    pub network_utilization: f64,
78    /// Disk utilization threshold (percentage)
79    pub disk_utilization: f64,
80    /// Response time threshold (milliseconds)
81    pub response_time: f64,
82    /// Error rate threshold (percentage)
83    pub error_rate: f64,
84    /// Availability threshold (percentage)
85    pub availability: f64,
86}
87
88/// Benchmarking configuration
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct BenchmarkingConfig {
91    /// Enable automated benchmarking
92    pub enabled: bool,
93    /// Benchmark frequency
94    pub frequency: Duration,
95    /// Benchmark types
96    pub benchmark_types: Vec<BenchmarkType>,
97    /// Baseline comparison
98    pub baseline_comparison: BaselineComparisonConfig,
99}
100
101/// Benchmark types
102#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
103pub enum BenchmarkType {
104    PerformanceStress,
105    LoadTesting,
106    CapacityTesting,
107    EnduranceTesting,
108    ScalabilityTesting,
109    QuantumBenchmark,
110    Custom(String),
111}
112
113/// Baseline comparison configuration
114#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct BaselineComparisonConfig {
116    /// Enable baseline comparison
117    pub enabled: bool,
118    /// Baseline update frequency
119    pub update_frequency: Duration,
120    /// Comparison tolerance (percentage)
121    pub tolerance: f64,
122    /// Historical baselines to maintain
123    pub historical_count: usize,
124}
125
126/// Dashboard configuration
127#[derive(Debug, Clone, Serialize, Deserialize)]
128pub struct DashboardConfig {
129    /// Dashboard name
130    pub name: String,
131    /// Dashboard type
132    pub dashboard_type: DashboardType,
133    /// Metrics to display
134    pub metrics: Vec<PerformanceMetric>,
135    /// Refresh rate
136    pub refresh_rate: Duration,
137    /// Layout configuration
138    pub layout: DashboardLayout,
139}
140
141/// Dashboard types
142#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
143pub enum DashboardType {
144    Overview,
145    Detailed,
146    RealTime,
147    Historical,
148    Comparative,
149    Custom(String),
150}
151
152/// Dashboard layout configuration
153#[derive(Debug, Clone, Serialize, Deserialize)]
154pub struct DashboardLayout {
155    /// Number of columns
156    pub columns: usize,
157    /// Widget configurations
158    pub widgets: Vec<WidgetConfig>,
159}
160
161/// Widget configuration
162#[derive(Debug, Clone, Serialize, Deserialize)]
163pub struct WidgetConfig {
164    /// Widget type
165    pub widget_type: WidgetType,
166    /// Position (row, column)
167    pub position: (usize, usize),
168    /// Size (width, height)
169    pub size: (usize, usize),
170    /// Metric to display
171    pub metric: PerformanceMetric,
172}
173
174/// Widget types
175#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
176pub enum WidgetType {
177    LineChart,
178    BarChart,
179    Gauge,
180    Counter,
181    Table,
182    Heatmap,
183    Custom(String),
184}
185
186impl Default for CloudPerformanceMonitoringConfig {
187    fn default() -> Self {
188        Self {
189            enabled: true,
190            metrics: vec![
191                PerformanceMetric::Latency,
192                PerformanceMetric::Throughput,
193                PerformanceMetric::CPUUtilization,
194                PerformanceMetric::MemoryUtilization,
195            ],
196            frequency: Duration::from_secs(30),
197            retention: Duration::from_secs(86400 * 30), // 30 days
198            real_time: RealTimeMonitoringConfig::default(),
199            thresholds: PerformanceThresholds::default(),
200            benchmarking: BenchmarkingConfig::default(),
201        }
202    }
203}
204
205impl Default for RealTimeMonitoringConfig {
206    fn default() -> Self {
207        Self {
208            enabled: true,
209            streaming_frequency: Duration::from_secs(5),
210            buffer_size: 1000,
211            aggregation_window: Duration::from_secs(60),
212            dashboards: vec![],
213        }
214    }
215}
216
217impl Default for PerformanceThresholds {
218    fn default() -> Self {
219        Self {
220            warning: ThresholdLevels::warning_defaults(),
221            critical: ThresholdLevels::critical_defaults(),
222            custom_thresholds: std::collections::HashMap::new(),
223        }
224    }
225}
226
227impl ThresholdLevels {
228    pub const fn warning_defaults() -> Self {
229        Self {
230            cpu_utilization: 70.0,
231            memory_utilization: 75.0,
232            network_utilization: 70.0,
233            disk_utilization: 80.0,
234            response_time: 1000.0, // 1 second
235            error_rate: 5.0,
236            availability: 95.0,
237        }
238    }
239
240    pub const fn critical_defaults() -> Self {
241        Self {
242            cpu_utilization: 85.0,
243            memory_utilization: 90.0,
244            network_utilization: 85.0,
245            disk_utilization: 95.0,
246            response_time: 5000.0, // 5 seconds
247            error_rate: 10.0,
248            availability: 90.0,
249        }
250    }
251}
252
253impl Default for BenchmarkingConfig {
254    fn default() -> Self {
255        Self {
256            enabled: false,
257            frequency: Duration::from_secs(86400), // daily
258            benchmark_types: vec![BenchmarkType::PerformanceStress],
259            baseline_comparison: BaselineComparisonConfig::default(),
260        }
261    }
262}
263
264impl Default for BaselineComparisonConfig {
265    fn default() -> Self {
266        Self {
267            enabled: true,
268            update_frequency: Duration::from_secs(86400 * 7), // weekly
269            tolerance: 10.0,
270            historical_count: 10,
271        }
272    }
273}