camel-prometheus
Prometheus metrics integration for rust-camel.
Overview
Implements MetricsCollector trait to export rust-camel metrics in Prometheus format.
New in 0.3.0: PrometheusService with Lifecycle trait for automatic server management.
Quick Start
Simple API (Recommended)
use PrometheusService;
use CamelContext;
// Prometheus server starts/stops automatically with context
let ctx = new
.with_lifecycle
.with_tracing;
ctx.start.await?;
// Server running on http://0.0.0.0:9090/metrics
ctx.stop.await?;
// Server stopped automatically
Manual Setup (Backward Compatible)
use ;
use CamelContext;
use Arc;
use SocketAddr;
let prometheus = new;
let ctx = with_metrics;
// Start server manually
let addr: SocketAddr = "0.0.0.0:9090".parse.unwrap;
spawn;
PrometheusService
PrometheusService implements the Lifecycle trait, which follows Apache Camel's Service pattern:
- Automatically starts HTTP server when
CamelContext.start()is called - Automatically stops when
CamelContext.stop()is called - Auto-registers
PrometheusMetricsasMetricsCollector
Metrics Exposed
| Metric | Type | Labels | Description |
|---|---|---|---|
camel_exchanges_total |
Counter | route |
Total exchanges processed |
camel_errors_total |
Counter | route, error_type |
Total errors |
camel_exchange_duration_seconds |
Histogram | route |
Exchange processing duration |
camel_queue_depth |
Gauge | route |
Current queue depth |
camel_circuit_breaker_state |
Gauge | route |
Circuit breaker state (0=closed, 1=open, 2=half_open) |
Endpoint
GET /metrics
Returns Prometheus text format metrics.
Architecture
PrometheusService (Lifecycle trait)
↓
├── Manages HTTP server lifecycle (start/stop)
├── Auto-registers MetricsCollector
└── MetricsServer (uses tower::Service internally via axum)
Note: Uses Lifecycle trait (not Service) to avoid confusion with tower::Service.
Health Endpoints
The PrometheusService exposes three health endpoints:
| Endpoint | Purpose | HTTP Status |
|---|---|---|
/healthz |
Liveness probe | 200 (always) |
/readyz |
Readiness probe | 200 if healthy, 503 if unhealthy |
/health |
Detailed health | 200 (always) |
Kubernetes Integration
livenessProbe:
httpGet:
path: /healthz
port: 9090
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /readyz
port: 9090
initialDelaySeconds: 5
periodSeconds: 5
Health Report Format