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 moreSource§impl Default for MetricsCollector
impl Default for MetricsCollector
Source§fn default() -> MetricsCollector
fn default() -> MetricsCollector
Auto Trait Implementations§
impl Freeze for MetricsCollector
impl !RefUnwindSafe for MetricsCollector
impl Send for MetricsCollector
impl Sync for MetricsCollector
impl Unpin for MetricsCollector
impl UnsafeUnpin for MetricsCollector
impl !UnwindSafe for MetricsCollector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more