Skip to content

Conversation

@lowhung
Copy link
Owner

@lowhung lowhung commented Dec 24, 2025

Summary

Adds support for exporting metrics in Prometheus text-based exposition format, enabling scraping by Prometheus or compatible monitoring systems.

Changes

  • Add prometheus feature flag to buswatch-sdk
  • Create prometheus.rs module with:
    • PrometheusConfig builder for configuration
    • PrometheusExporter for storing and rendering metrics
    • format_prometheus() function to convert snapshots to Prometheus format
  • Add Output::prometheus() variant
  • Integrate HTTP server using hyper to serve metrics endpoint
  • Include /health and /healthz endpoints for Kubernetes probes

Metrics Exported

  • buswatch_read_count (counter) - Total messages read
  • buswatch_write_count (counter) - Total messages written
  • buswatch_read_backlog (gauge) - Unread message count
  • buswatch_read_pending_seconds (gauge) - Read wait time
  • buswatch_write_pending_seconds (gauge) - Write wait time
  • buswatch_read_rate_per_second (gauge) - Read throughput
  • buswatch_write_rate_per_second (gauge) - Write throughput
  • buswatch_snapshot_timestamp_seconds (gauge) - Snapshot timestamp

All metrics include module and topic labels.

Usage

use buswatch_sdk::{Instrumentor, Output};
use buswatch_sdk::prometheus::PrometheusConfig;

#[tokio::main]
async fn main() {
    let config = PrometheusConfig::builder()
        .listen_addr("0.0.0.0:9090")
        .metrics_path("/metrics")
        .build();

    let instrumentor = Instrumentor::builder()
        .output(Output::prometheus(config))
        .build();

    let handle = instrumentor.register("my-service");
    handle.record_read("events", 100);

    instrumentor.start();

    // Metrics available at http://localhost:9090/metrics
}

Closes #10

- Add 'prometheus' feature flag to buswatch-sdk
- Add prometheus.rs module with PrometheusConfig, PrometheusExporter
- Implement format_prometheus() for Prometheus text exposition format
- Add HTTP server using hyper to serve /metrics endpoint
- Add Output::prometheus() variant and integration with Instrumentor
- Include /health and /healthz endpoints for liveness checks

Metrics exported:
- buswatch_read_count (counter)
- buswatch_write_count (counter)
- buswatch_read_backlog (gauge)
- buswatch_read_pending_seconds (gauge)
- buswatch_write_pending_seconds (gauge)
- buswatch_read_rate_per_second (gauge)
- buswatch_write_rate_per_second (gauge)
- buswatch_snapshot_timestamp_seconds (gauge)

All metrics include module and topic labels.

Closes #10
- Update buswatch-sdk/README.md with Prometheus output section and feature table
- Add Prometheus integration example to SDK README
- Update main README.md features list to include Prometheus
- Add Prometheus feature to CHANGELOG under Unreleased
@lowhung lowhung merged commit 5740e98 into main Dec 24, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(sdk): Add Prometheus exposition format export

2 participants