pub struct MetricsCollector { /* private fields */ }Expand description
Metrics collector for the simulator.
Provides comprehensive metrics collection including:
- Request/response counters and timings
- Device and connection tracking
- System resource monitoring (CPU, memory)
- Protocol-specific metrics
Implementations§
Source§impl MetricsCollector
impl MetricsCollector
Sourcepub fn new() -> MetricsCollector
pub fn new() -> MetricsCollector
Create a new metrics collector with a fresh registry.
Sourcepub fn global() -> &'static MetricsCollector
pub fn global() -> &'static MetricsCollector
Get the global metrics collector instance.
This returns a shared instance that uses the global registry. Use this when you want all metrics to be collected in one place.
Sourcepub fn with_registry(registry: Registry) -> MetricsCollector
pub fn with_registry(registry: Registry) -> MetricsCollector
Create a metrics collector with a custom registry.
Sourcepub fn record_request(&self, protocol: &str, operation: &str)
pub fn record_request(&self, protocol: &str, operation: &str)
Record a request by protocol and operation.
This is the primary method for tracking request counts and should be
used in conjunction with record_request_duration or time_request.
Sourcepub fn record_request_duration(
&self,
protocol: &str,
operation: &str,
duration: Duration,
)
pub fn record_request_duration( &self, protocol: &str, operation: &str, duration: Duration, )
Record a request duration.
Sourcepub fn time_request(&self, protocol: &str, operation: &str) -> RequestTimer
pub fn time_request(&self, protocol: &str, operation: &str) -> RequestTimer
Sourcepub fn record_message(&self, protocol: &str, direction: &str)
pub fn record_message(&self, protocol: &str, direction: &str)
Record a message (for protocol-level message tracking).
Sourcepub fn record_read(&self, protocol: &str, success: bool, duration: Duration)
pub fn record_read(&self, protocol: &str, success: bool, duration: Duration)
Record a read operation with timing and status.
Sourcepub fn record_write(&self, protocol: &str, success: bool, duration: Duration)
pub fn record_write(&self, protocol: &str, success: bool, duration: Duration)
Record a write operation with timing and status.
Sourcepub fn record_error(&self, protocol: &str, error_type: &str)
pub fn record_error(&self, protocol: &str, error_type: &str)
Record an error by protocol and error type.
Sourcepub fn record_tick(&self, duration: Duration)
pub fn record_tick(&self, duration: Duration)
Record an engine tick with duration.
Sourcepub fn record_latency(&self, protocol: &str, latency: Duration)
pub fn record_latency(&self, protocol: &str, latency: Duration)
Record message latency.
Sourcepub fn record_event(&self, event_type: &str)
pub fn record_event(&self, event_type: &str)
Record an event by type.
Sourcepub fn set_devices_active(&self, count: i64)
pub fn set_devices_active(&self, count: i64)
Set the number of active devices.
Sourcepub fn set_connections_active(&self, protocol: &str, count: i64)
pub fn set_connections_active(&self, protocol: &str, count: i64)
Set active connections for a protocol.
Sourcepub fn inc_connections(&self, protocol: &str)
pub fn inc_connections(&self, protocol: &str)
Increment active connections for a protocol.
Sourcepub fn dec_connections(&self, protocol: &str)
pub fn dec_connections(&self, protocol: &str)
Decrement active connections for a protocol.
Sourcepub fn set_points_total(&self, count: i64)
pub fn set_points_total(&self, count: i64)
Set total data points.
Sourcepub fn set_device_points(&self, protocol: &str, device_id: &str, count: i64)
pub fn set_device_points(&self, protocol: &str, device_id: &str, count: i64)
Set data points for a specific device.
Sourcepub fn remove_device_points(&self, protocol: &str, device_id: &str)
pub fn remove_device_points(&self, protocol: &str, device_id: &str)
Remove device points metrics (when device is removed).
Sourcepub fn set_memory_bytes(&self, bytes: i64)
pub fn set_memory_bytes(&self, bytes: i64)
Set memory usage in bytes.
Sourcepub fn set_cpu_percent(&self, percent: f64)
pub fn set_cpu_percent(&self, percent: f64)
Set CPU usage percentage (0-100).
Sourcepub fn update_system_metrics(&self, memory_bytes: i64, cpu_percent: f64)
pub fn update_system_metrics(&self, memory_bytes: i64, cpu_percent: f64)
Update system metrics (memory and CPU).
This is a convenience method that updates both memory and CPU metrics.
Sourcepub fn snapshot(&self) -> MetricsSnapshot
pub fn snapshot(&self) -> MetricsSnapshot
Get a snapshot of current metrics.
Sourcepub fn detailed_snapshot(&self) -> DetailedMetricsSnapshot
pub fn detailed_snapshot(&self) -> DetailedMetricsSnapshot
Get a detailed snapshot with additional information.
Sourcepub fn export_prometheus(&self) -> String
pub fn export_prometheus(&self) -> String
Export metrics in Prometheus text format.
Sourcepub fn export_global_prometheus() -> String
pub fn export_global_prometheus() -> String
Export metrics from the global registry.
Trait Implementations§
Source§impl Clone for MetricsCollector
impl Clone for MetricsCollector
Source§fn clone(&self) -> MetricsCollector
fn clone(&self) -> MetricsCollector
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more