The gateway now ships in the
praisonai-bot package. praisonai serve gateway still works exactly as documented here; for a standalone install see praisonai-bot Migration.GET /metrics on the PraisonAI gateway to feed Prometheus — counters, gauges, and latency histograms for every hop of the message flow, zero new dependencies.
GET /metrics while messaging the gateway; counters, gauges, and latency histograms record inbound, agent, and outbound hops.
Quick Start
1
Start the gateway with auth_token set
2
Scrape the metrics endpoint
3
Read the Prometheus exposition output
How It Works
Gauges are sampled on every scrape — not pushed on a timer. The/metrics endpoint calls _refresh_metric_gauges() before rendering, so active_sessions and channel_recoveries always reflect the live gateway state.
Configuration Options
Pick the metric type that matches what you are measuring.Authentication
The/metrics endpoint uses the same _check_auth gate as other operational endpoints (e.g. /info).
Returns
401 if token is required but missing; 403 on token mismatch.
If
auth_token is not set in the gateway config, the endpoint is open to all callers. Set auth_token before binding to non-loopback addresses.Counters
Gauges
Labels: Counters and gauges accept an arbitrary
labels dict (string→string). Channel-scoped metrics use labels={"channel": <name>}. Labels are rendered as sorted, deterministic name{a="b",c="d"} value.
messages_inbound_total is incremented on every inbound message via _record_channel_inbound, carrying a single channel label — one time series per configured channel (including Telegram polling injected through _inject_routing_handler). The praisonai gateway test --check-inbound command scrapes this counter to compute a per-window delta as live-delivery proof. See Inbound tier.Histograms
Histograms record latency distributions per hop, so you can compute p50/p95/p99 straight from/metrics.
Five histograms are pre-registered with help text:
observe(name, seconds, buckets=DEFAULT_BUCKETS, labels=None) records a duration into cumulative buckets plus running _sum / _count. timer(name, ...) is a context manager that times its body with time.perf_counter() and calls observe. Both default to DEFAULT_BUCKETS:
Histogram invariants (enforced by the SDK):
- Buckets must be finite and strictly increasing —
NaN,±Inf, duplicates, or decreases raiseValueError. - The
+Infbucket is appended automatically at render time — supply only finite bounds. - A histogram
nameis pinned to its first bucket set; re-observing the same name with different buckets raisesValueError. "le"is a reserved label and cannot appear in yourlabelsdict.
Common Patterns
Recording a custom counter
Fetching a JSON snapshot in tests
Prometheus scrape config
Using GatewayMetrics directly
Timing a stage with timer()
Recording a measured duration with observe()
Custom buckets for a different latency profile
ValueError.
Best Practices
Set auth_token before binding to non-loopback
Set auth_token before binding to non-loopback
Always configure
auth_token in gateway.yaml when your gateway binds to 0.0.0.0 or a public address. Without it, /metrics is open to the network.Use a scrape interval of 5s or longer
Use a scrape interval of 5s or longer
Gauges are sampled on each scrape. Scraping more frequently than every 5 seconds wastes resources without adding useful resolution — gateway state changes at human timescales.
Alert on outbound_failed_total and channel_restarts_total
Alert on outbound_failed_total and channel_restarts_total
These two counters surface delivery problems immediately. Configure Prometheus alerting rules on their rates:
Don't depend on push frequency for gauges
Don't depend on push frequency for gauges
active_sessions, outbox_depth, and approval_pending are point-in-time samples taken at scrape time — they are not time-averaged. Use them as snapshots, not as rate inputs.Alert on p95/p99 turn latency
Alert on p95/p99 turn latency
Turn-latency histograms feed SLOs directly. Use
histogram_quantile over the _bucket rate to alert on p95:Histograms now cover turn / LLM / tool / queue-wait / outbound latency distributions — use them for SLOs (p50/p95/p99). For per-stage error spans and cross-service correlation, attach a hook via Gateway Tracing Hook.
Related
Bind-Aware Auth
The bind-aware loopback bypass (permissive on loopback by default) that also protects
/metrics — understand how token auth and the loopback bypass work together.Correlation IDs
Join ingress, session, and agent-run logs on one stable id per message.
Gateway Server
Multi-bot WebSocket gateway — the host that exposes
/metrics.BotOS
The full bot operating system layer above the gateway.
Hot-Reload Observability
Last reload outcome, watcher liveness, and config drift via
health().Tracing Hook
The other observability rail — per-stage OpenTelemetry spans alongside these counters.

