Observability
Goal: Production monitoring and resilience.
Prometheus metrics
import { live } from 'svelte-realtime/server';
import { createMetricsRegistry } from 'svelte-adapter-uws-extensions/prometheus';
const registry = createMetricsRegistry();
live.metrics(registry); This registers:
| Metric | Type | Description |
|---|---|---|
svelte_realtime_rpc_total | counter | RPC call count by path and status |
svelte_realtime_rpc_duration_seconds | histogram | RPC latency by path |
svelte_realtime_rpc_errors_total | counter | RPC errors by path and code |
svelte_realtime_stream_subscriptions | gauge | Active stream subscriptions by topic |
svelte_realtime_cron_total | counter | Cron execution count |
svelte_realtime_cron_errors_total | counter | Cron errors by path |
Zero overhead when not called.
Circuit breaker
Wrap external dependencies so failures don’t cascade.
import { createBreaker } from 'svelte-adapter-uws-extensions/breaker';
const dbBreaker = createBreaker({
threshold: 5, // open after 5 consecutive failures
resetMs: 30000 // try again after 30 seconds
});
export const items = live.stream('items',
live.breaker({ breaker: dbBreaker, fallback: [] }, async (ctx) => {
return db.items.list();
})
); When the database is down, subscribers get [] instead of errors. The breaker auto-resets after 30 seconds.
What to monitor in production
- RPC latency - p99 should stay under 50ms for most handlers
- Stream subscription count - tracks how many clients are connected to each topic
- Error rates - spike = something broke
- Connection count - uWebSockets.js handles thousands, but watch for leaks
- Memory -
process.memoryUsage()- watch for unbounded growth in replay buffers
Related guides
- Scaling Guide - step-by-step from single instance to distributed
- Scaling and Resilience - when and why you need extensions
- Distributed Pub/Sub - Redis pub/sub setup
- Replay and Presence - persistent replay and cross-instance presence
- Extensions package - full API reference
Was this page helpful?