Crate buswatch_sdk

Crate buswatch_sdk 

Source
Expand description

§buswatch-sdk

Instrumentation SDK for emitting message bus metrics to buswatch.

This crate provides a simple API for instrumenting any message bus system to emit metrics that can be consumed by buswatch or other monitoring tools.

§Quick Start

use buswatch_sdk::{Instrumentor, Output};
use std::time::Duration;

#[tokio::main]
async fn main() {
    // Create an instrumentor that emits snapshots every second
    let instrumentor = Instrumentor::builder()
        .output(Output::file("metrics.json"))
        .interval(Duration::from_secs(1))
        .build();

    // Register a module and get a handle for recording metrics
    let handle = instrumentor.register("my-service");

    // Record metrics as your service processes messages
    handle.record_read("orders.new", 1);
    handle.record_write("orders.processed", 1);

    // Start background emission (non-blocking)
    instrumentor.start();

    // ... your application runs ...
}

§Features

  • Simple API: Just record_read() and record_write()
  • Multiple outputs: File, TCP, or custom channel
  • Background emission: Automatic periodic snapshots
  • Thread-safe: Use from any thread or async task
  • Low overhead: Lock-free counters where possible

Structs§

Instrumentor
The main entry point for instrumenting a message bus.
InstrumentorBuilder
Builder for configuring an Instrumentor.
Microseconds
Duration in microseconds.
ModuleHandle
A handle for recording metrics for a specific module.
ModuleMetrics
Metrics for a single module/consumer/producer in the message bus.
ReadMetrics
Metrics for reading from a topic (subscription/consumer).
Snapshot
A point-in-time snapshot of message bus metrics.
WriteMetrics
Metrics for writing to a topic (publication/producer).

Enums§

Output
Output destination for snapshots.