pub struct NodeMetrics {Show 14 fields
pub active_connections: Gauge,
pub total_connections: Counter,
pub failed_connections: Counter,
pub messages_sent: Counter,
pub messages_received: Counter,
pub messages_dropped: Counter,
pub message_size_bytes: Histogram,
pub message_latency_ms: Histogram,
pub state_sync_latency_ms: Histogram,
pub memory_usage_bytes: Gauge,
pub cpu_usage_percent: Gauge,
pub time_drift_ms: Gauge,
pub state_divergence_count: Gauge,
pub quarantine_buffer_size: Gauge,
}Expand description
Core metrics for monitoring ELARA node health and performance.
This struct provides a centralized collection of all key metrics that should be monitored in a production ELARA deployment. Metrics are organized into categories:
- Connection metrics: Track connection lifecycle and health
- Message metrics: Track message throughput and reliability
- Latency metrics: Track performance characteristics
- Resource metrics: Track system resource usage
- Protocol metrics: Track protocol-specific health indicators
§Example
use elara_runtime::observability::metrics::{MetricsRegistry, NodeMetrics};
let registry = MetricsRegistry::new();
let metrics = NodeMetrics::new(®istry);
// Track connections
metrics.active_connections.inc();
metrics.total_connections.inc();
// Track messages
metrics.messages_sent.inc();
metrics.message_latency_ms.observe(42.5);
// Track resources
metrics.memory_usage_bytes.set(1024 * 1024 * 512); // 512 MB
metrics.cpu_usage_percent.set(45);Fields§
§active_connections: GaugeNumber of currently active connections.
total_connections: CounterTotal number of connections established since node start.
failed_connections: CounterTotal number of failed connection attempts.
messages_sent: CounterTotal number of messages sent.
messages_received: CounterTotal number of messages received.
messages_dropped: CounterTotal number of messages dropped (e.g., due to queue overflow).
message_size_bytes: HistogramDistribution of message sizes in bytes.
message_latency_ms: HistogramDistribution of message processing latency in milliseconds.
state_sync_latency_ms: HistogramDistribution of state synchronization latency in milliseconds.
memory_usage_bytes: GaugeCurrent memory usage in bytes.
cpu_usage_percent: GaugeCurrent CPU usage as a percentage (0-100).
time_drift_ms: GaugeCurrent time drift from reference time in milliseconds. Positive values indicate local clock is ahead, negative values indicate behind.
state_divergence_count: GaugeNumber of state divergences detected. This tracks instances where state reconciliation found inconsistencies.
quarantine_buffer_size: GaugeNumber of events in the quarantine buffer. Events are quarantined when they have missing dependencies.
Implementations§
Source§impl NodeMetrics
impl NodeMetrics
Sourcepub fn new(registry: &MetricsRegistry) -> Self
pub fn new(registry: &MetricsRegistry) -> Self
Creates a new NodeMetrics instance and registers all metrics with the provided registry.
This constructor initializes all core metrics with appropriate types and bucket
configurations for histograms. All metrics are registered with the provided
MetricsRegistry and can be accessed through the returned struct.
§Histogram Buckets
- message_latency_ms: Buckets optimized for typical message processing times (1ms to 5 seconds)
- state_sync_latency_ms: Buckets optimized for state synchronization times (10ms to 30 seconds)
- message_size_bytes: Buckets optimized for typical message sizes (64 bytes to 1 MB)
§Arguments
registry- The metrics registry to register all metrics with
§Example
use elara_runtime::observability::metrics::{MetricsRegistry, NodeMetrics};
let registry = MetricsRegistry::new();
let metrics = NodeMetrics::new(®istry);
// Metrics are now registered and ready to use
metrics.active_connections.inc();Sourcepub fn active_connections(&self) -> &Gauge
pub fn active_connections(&self) -> &Gauge
Returns a reference to the active connections gauge.
Sourcepub fn total_connections(&self) -> &Counter
pub fn total_connections(&self) -> &Counter
Returns a reference to the total connections counter.
Sourcepub fn failed_connections(&self) -> &Counter
pub fn failed_connections(&self) -> &Counter
Returns a reference to the failed connections counter.
Sourcepub fn messages_sent(&self) -> &Counter
pub fn messages_sent(&self) -> &Counter
Returns a reference to the messages sent counter.
Sourcepub fn messages_received(&self) -> &Counter
pub fn messages_received(&self) -> &Counter
Returns a reference to the messages received counter.
Sourcepub fn messages_dropped(&self) -> &Counter
pub fn messages_dropped(&self) -> &Counter
Returns a reference to the messages dropped counter.
Sourcepub fn message_size_bytes(&self) -> &Histogram
pub fn message_size_bytes(&self) -> &Histogram
Returns a reference to the message size histogram.
Sourcepub fn message_latency_ms(&self) -> &Histogram
pub fn message_latency_ms(&self) -> &Histogram
Returns a reference to the message latency histogram.
Sourcepub fn state_sync_latency_ms(&self) -> &Histogram
pub fn state_sync_latency_ms(&self) -> &Histogram
Returns a reference to the state sync latency histogram.
Sourcepub fn memory_usage_bytes(&self) -> &Gauge
pub fn memory_usage_bytes(&self) -> &Gauge
Returns a reference to the memory usage gauge.
Sourcepub fn cpu_usage_percent(&self) -> &Gauge
pub fn cpu_usage_percent(&self) -> &Gauge
Returns a reference to the CPU usage gauge.
Sourcepub fn time_drift_ms(&self) -> &Gauge
pub fn time_drift_ms(&self) -> &Gauge
Returns a reference to the time drift gauge.
Sourcepub fn state_divergence_count(&self) -> &Gauge
pub fn state_divergence_count(&self) -> &Gauge
Returns a reference to the state divergence count gauge.
Sourcepub fn quarantine_buffer_size(&self) -> &Gauge
pub fn quarantine_buffer_size(&self) -> &Gauge
Returns a reference to the quarantine buffer size gauge.
Trait Implementations§
Source§impl Clone for NodeMetrics
impl Clone for NodeMetrics
Source§fn clone(&self) -> NodeMetrics
fn clone(&self) -> NodeMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for NodeMetrics
impl RefUnwindSafe for NodeMetrics
impl Send for NodeMetrics
impl Sync for NodeMetrics
impl Unpin for NodeMetrics
impl UnsafeUnpin for NodeMetrics
impl UnwindSafe for NodeMetrics
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request