Monitoring8 May 20254 min read

WebSocket Monitoring: Keeping Long-Lived Connections Healthy

A WebSocket connection can appear established in your load balancer metrics while the application layer has gone silent. Chat messages stop delivering. Live dashboards freeze. Users see stale data. And your HTTP health check is green.

MonitoringUptime MonitoringWebsite MonitoringApi MonitoringCron Job Monitoring
Monitoring

HTTP checks assume request-response. WebSockets are persistent connections that can silently break while reporting healthy. Here is how to monitor connections that never close.

Why HTTP monitoring is not enough for WebSockets

HTTP monitoring tests a request-response cycle. WebSocket monitoring needs to test: 1. The connection can be established 2. Messages can be sent and received (round-trip) 3. The connection stays alive over time (no silent disconnects) 4. Reconnection works when the server restarts

Most uptime monitors test only #1 and miss the rest.

Heartbeat pings inside WebSocket connections

Implement application-level heartbeats: ```javascript const ws = new WebSocket('wss://your-app.com/ws'); let lastPong = Date.now();

setInterval(() => { ws.send(JSON.stringify({ type: 'ping' })); if (Date.now() - lastPong > 30000) { // Server hasn't responded in 30s — connection is dead ws.close(); reconnect(); } }, 15000);

ws.onmessage = (msg) => { const data = JSON.parse(msg.data); if (data.type === 'pong') lastPong = Date.now(); }; ```

External WebSocket monitoring

Use a scheduled function that opens a WebSocket connection, sends a test message, waits for a response, then pings AlertsDock: ```python async def check_websocket(): async with websockets.connect('wss://your-app.com/ws') as ws: await ws.send(json.dumps({'type': 'ping'})) response = await asyncio.wait_for(ws.recv(), timeout=5) if json.loads(response)['type'] == 'pong': requests.get('https://alertsdock.com/ping/{uuid}') ```

Schedule this as a cron job that runs every 5 minutes.

Connection count monitoring

Monitor active WebSocket connection count alongside your HTTP monitoring: - Alert when connection count drops to zero (server restarted, connections not reconnecting) - Alert when connection count spikes 5x (potential DDoS or connection leak)

Graceful reconnection

Every WebSocket client should implement exponential backoff reconnection: ```javascript let reconnectDelay = 1000; // start at 1s function reconnect() { setTimeout(() => { connect(); reconnectDelay = Math.min(reconnectDelay * 2, 30000); }, reconnectDelay); } ```

This article is available across the supported locale routes — use the language switcher above to change.

Feature Guide

Uptime Monitoring

AlertsDock gives teams uptime monitoring for websites, APIs, TCP checks, DNS checks, SSL expiry, and fast alert routing without enterprise overhead.

Read guide

Alternative Page

UptimeRobot Alternative

Compare AlertsDock with UptimeRobot for teams that want uptime monitoring plus heartbeat monitoring, status pages, webhook inspection, and per-resource alert routing.

See comparison
AD
AlertsDock Team
8 May 2025
Try AlertsDock free