How to Monitor WebSocket Connections for Real-Time Applications
Monitorion
Monitoring Insights
If your application relies on WebSockets — chat applications, trading platforms, live dashboards, multiplayer games, collaborative editing tools — then HTTP monitoring alone is not enough. Your HTTP endpoint might return 200 OK while your WebSocket server is completely down. Users see a connected-looking interface that never receives real-time data. The chat window loads but no messages arrive. The trading dashboard renders but prices are frozen. The collaborative document appears but edits from other users never appear. From the user's perspective, the app is broken — but your HTTP monitor says everything is fine.
Why WebSocket Monitoring Is Different
WebSocket connections are fundamentally different from HTTP requests. They are long-lived, bidirectional, and stateful. An HTTP health check confirms the server is running, but it does not verify that:
- The WebSocket handshake completes successfully (the HTTP 101 upgrade)
- The connection remains stable after opening
- Messages can be sent and received in both directions
- The server responds within acceptable latency
- Authentication and session handling work correctly over the persistent connection
Many applications serve HTTP and WebSocket traffic from different processes or even different servers. Your Nginx reverse proxy might handle HTTP perfectly while the WebSocket upstream (a separate Node.js or Go process) has crashed. Without dedicated WebSocket monitoring, this failure mode is invisible to your monitoring stack.
Common WebSocket Failure Modes
Understanding how WebSocket connections fail helps you configure effective monitoring:
- Handshake failure — the server refuses the HTTP upgrade request. Common causes: misconfigured reverse proxy (Nginx requires specific
proxy_set_header UpgradeandConnectiondirectives), expired TLS certificates on the WebSocket endpoint, or the WebSocket process has crashed while the HTTP server continues running. - Connection timeout — the handshake initiates but never completes. This often indicates network-level issues: a firewall blocking the upgrade, a load balancer that does not support WebSocket connections, or an overloaded server that cannot accept new connections.
- Silent disconnection — the connection opens successfully but drops after a few seconds. Common when intermediate proxies or load balancers have short idle timeouts that close WebSocket connections prematurely. AWS ALB defaults to 60 seconds; Cloudflare defaults to 100 seconds.
- Message delivery failure — the connection is open but messages are not delivered. The WebSocket process is alive but the message broker, pub/sub system, or database it depends on has failed. The connection looks healthy but no data flows through it.
- Partial functionality — the server accepts connections and responds to pings, but business logic is broken. For example, a chat server that connects but cannot deliver messages because Redis pub/sub is down.
Setting Up WebSocket Monitoring in Monitorion
Go to Monitors → New Monitor → WebSocket and configure:
- URL — your WebSocket endpoint (e.g.,
wss://api.example.com/ws). Supports bothws://andwss://(TLS). Always usewss://for production endpoints — unencrypted WebSocket connections are blocked by many proxies and browsers. - Message to Send (optional) — a test message to send after connecting. The monitor verifies it receives a response. This tests not just connectivity but actual server-side message processing.
- Expected Response (optional) — text the response should contain. Useful for echo servers, ping/pong protocols, or servers that send a welcome message on connection.
- Timeout — how long to wait for the handshake and response before marking the check as failed. Set this to at least 2x your expected handshake time. For most applications, 10-15 seconds is appropriate.
What Monitorion Checks
Each WebSocket check performs a complete lifecycle test that mirrors what a real client experiences:
- DNS resolution — resolves the hostname. A failure here indicates DNS issues, not WebSocket issues.
- TCP connection — establishes the underlying TCP connection to the server.
- TLS handshake (for wss://) — validates the SSL certificate and negotiates encryption.
- WebSocket upgrade — sends the HTTP upgrade request and verifies the server responds with 101 Switching Protocols.
- Message exchange — sends your configured test message and waits for a response that matches your expected pattern.
- Clean close — properly closes the connection with a close frame, verifying the server handles disconnection gracefully.
The monitor reports: connection success or failure, total latency (time from connection initiation to first message received), and whether the expected response was matched. Response time trends help you identify gradual degradation — a WebSocket server under memory pressure often shows increasing connection latency days before it crashes.
Monitoring Strategies by Application Type
Chat Applications
Send a ping message and expect a pong response. Set a 60-second check interval — chat users notice disconnections quickly, and a 60-second detection window limits the impact. If your chat server sends a welcome message on connection (many do, with user count or channel info), use that as your expected response to verify the full application stack is functional.
Trading and Financial Platforms
Send a subscribe message for a known instrument or market data feed, and verify you receive a price update or acknowledgment. Use 30-second intervals — stale prices mean financial risk for your users. Consider monitoring from multiple regions to ensure low-latency data delivery across geographies. Financial WebSocket connections are also subject to regulatory requirements around data freshness.
Live Dashboards and Analytics
Connect and verify that any message is received within the timeout period. If your dashboard pushes periodic metric updates (every 5 or 10 seconds), the monitor confirms data is flowing. Set the timeout slightly longer than your push interval to avoid false positives during normal update cycles.
Collaborative Editing Tools
Send a test operation (a no-op cursor move or a presence update) and verify the server acknowledges it. Collaborative editing depends on operational transformation or CRDT synchronization — if the server cannot process operations, the editing experience breaks even though the connection is technically alive.
IoT and Telemetry
For IoT gateways that accept WebSocket connections from devices, send a simulated device registration or telemetry payload. Verify the server acknowledges the data. IoT WebSocket servers often run at high connection counts, and monitoring helps you detect when the server approaches its connection limit.
Best Practices
Monitor the WebSocket endpoint separately from your HTTP API. Even if they share a domain, they may run on different processes, behind different load balancer rules, or on different server instances. A single HTTP health check does not cover WebSocket functionality.
Use a meaningful test message. A simple ping/pong verifies connectivity, but sending a message that exercises your business logic (subscribe to a channel, request initial state) catches application-layer failures that a ping would miss.
Set alerts to match user impact. For real-time applications, even 2 minutes of WebSocket downtime is noticeable. Route WebSocket monitor alerts to the same high-priority channels you use for your main HTTP monitors — Slack, PagerDuty, or SMS depending on severity.
Combine with HTTP monitoring. When your WebSocket monitor fails but your HTTP monitor passes, you know the issue is specific to the WebSocket layer — a crashed process, a proxy misconfiguration, or a resource exhaustion issue on the WebSocket server. When both fail, the problem is broader (server down, network issue, DNS failure). This diagnostic layering saves significant troubleshooting time.
WebSocket monitoring is available on Pro plans and above. Set up your first WebSocket monitor and ensure your real-time features actually stay real-time — because a connected-looking interface with no data is worse than an honest error page.
Enjoyed this post?
Get monitoring tips and product updates delivered to your inbox.