Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Metrics

rsActor provides optional per-actor performance metrics. Enable with the metrics feature flag:

[dependencies]
rsactor = { version = "0.14", features = ["metrics"] }

Tracked Metrics

MetricTypeDescription
message_countu64Total messages processed
avg_processing_timeDurationAverage message processing time
max_processing_timeDurationMaximum processing time observed
error_countu64Total errors during message handling
uptimeDurationTime since actor was started
last_activityOption<SystemTime>Timestamp of last message processing

Usage

Snapshot

Get all metrics at once:

#![allow(unused)]
fn main() {
let metrics = actor_ref.metrics();
println!("Messages: {}", metrics.message_count);
println!("Avg time: {:?}", metrics.avg_processing_time);
println!("Max time: {:?}", metrics.max_processing_time);
println!("Errors: {}", metrics.error_count);
println!("Uptime: {:?}", metrics.uptime);
println!("Last activity: {:?}", metrics.last_activity);
}

Individual Accessors

#![allow(unused)]
fn main() {
let count = actor_ref.message_count();
let avg = actor_ref.avg_processing_time();
let max = actor_ref.max_processing_time();
let errors = actor_ref.error_count();
let uptime = actor_ref.uptime();
let last = actor_ref.last_activity();
}

Design

  • Lock-free: Uses AtomicU64 counters for zero-contention updates
  • Zero overhead when disabled: When the metrics feature is not enabled, no metrics code is compiled
  • Automatic collection: Metrics are collected transparently during message processing
  • Post-mortem analysis: Metrics survive actor drop via ActorWeak (strong reference to metrics collector)

Philosophy

rsActor exposes raw metrics data. How you monitor, alert, or visualize this data is your responsibility. You can integrate with any monitoring system (Prometheus, Grafana, custom dashboards, etc.).

Running the Example

cargo run --example metrics_demo --features metrics