Weave Swarm
Metrics
Swarm metrics in Weave Swarm — peer counts, connection health, event throughput, and per-topic histograms.
Purpose
Topic swarm for peer IDs, topic IDs, join/update options, events, priorities, connection state, and metrics.
This page follows the real source shape for Weave Swarm and explains the workflow a developer is likely to use first.
Developer workflow
Start from the smallest constructor or builder, perform one meaningful operation, inspect the returned state, then add the relevant policy, storage, or network integration. The examples below should be expanded whenever the crate API changes.
Primary types to know
BackoffConfig— network/weave-swarm/src/config.rsConnection— network/weave-swarm/src/connection.rsConnectionStats— network/weave-swarm/src/connection.rsJoinOptions— network/weave-swarm/src/topic.rsLimitsConfig— network/weave-swarm/src/config.rsNatConfig— network/weave-swarm/src/config.rsPeerId— network/weave-swarm/src/connection.rsPriority— network/weave-swarm/src/priority.rsSwarm— network/weave-swarm/src/swarm.rsSwarmConfig— network/weave-swarm/src/config.rsSwarmMetrics— network/weave-swarm/src/metrics.rsTelemetryConfig— network/weave-swarm/src/config.rs
Example shape
use weave_swarm::{Swarm, SwarmConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let swarm = Swarm::new(SwarmConfig::default()).await?;
// export_metrics_text renders Prometheus exposition-format text for the
// requested namespace, ready to surface via /metrics.
let metrics_text = swarm.export_metrics_text("weave_swarm");
println!(
"topic_count={} connection_count={} prometheus_bytes={}",
swarm.topic_count(),
swarm.connection_count(),
metrics_text.len(),
);
// A tiny grep confirms the namespace prefix is applied.
assert!(metrics_text.contains("weave_swarm"));
Ok(())
}