pub struct Snapshot {
pub version: SchemaVersion,
pub timestamp_ms: u64,
pub modules: BTreeMap<String, ModuleMetrics>,
}Expand description
A point-in-time snapshot of message bus metrics.
This is the top-level type that captures the state of all modules in a message bus system. Snapshots are typically emitted periodically (e.g., every second) and consumed by monitoring tools like buswatch.
§Example
use buswatch_types::Snapshot;
use std::time::Duration;
let snapshot = Snapshot::builder()
.module("order-service", |m| {
m.read("orders.new", |r| r.count(500).backlog(10))
.write("orders.validated", |w| w.count(495))
})
.build();
// Serialize with serde (requires "serde" feature)
// let json = serde_json::to_string(&snapshot)?;Fields§
§version: SchemaVersionSchema version for forward compatibility.
timestamp_ms: u64Unix timestamp in milliseconds when this snapshot was taken.
modules: BTreeMap<String, ModuleMetrics>Metrics for each module, keyed by module name.
Implementations§
Source§impl Snapshot
impl Snapshot
Sourcepub fn with_timestamp(timestamp_ms: u64) -> Self
pub fn with_timestamp(timestamp_ms: u64) -> Self
Create a new snapshot with a specific timestamp.
Sourcepub fn builder() -> SnapshotBuilder
pub fn builder() -> SnapshotBuilder
Create a builder for constructing snapshots.
Sourcepub fn get(&self, module: &str) -> Option<&ModuleMetrics>
pub fn get(&self, module: &str) -> Option<&ModuleMetrics>
Get metrics for a specific module.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&String, &ModuleMetrics)>
pub fn iter(&self) -> impl Iterator<Item = (&String, &ModuleMetrics)>
Iterate over all modules.
Sourcepub fn total_reads(&self) -> u64
pub fn total_reads(&self) -> u64
Total messages read across all modules.
Sourcepub fn total_writes(&self) -> u64
pub fn total_writes(&self) -> u64
Total messages written across all modules.
Trait Implementations§
impl StructuralPartialEq for Snapshot
Auto Trait Implementations§
impl Freeze for Snapshot
impl RefUnwindSafe for Snapshot
impl Send for Snapshot
impl Sync for Snapshot
impl Unpin for Snapshot
impl UnwindSafe for Snapshot
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
Mutably borrows from an owned value. Read more