A Prometheus exporter for monitoring WebSocket connections to blockchain nodes. This exporter focuses on establishing connections to WebSocket endpoints and measuring connection success and latency.
This WebSocket Connection Exporter:
- Establishes WebSocket connections to blockchain node endpoints
- Measures connection establishment time and success
- Exposes a
/probeendpoint compatible with VictoriaMetrics VMProbe - Provides focused metrics about connection success and latency
The exporter provides these metrics:
probe_success- Overall success of the probeprobe_duration_seconds- Total probe durationprobe_websocket_up- Success of the WebSocket connection establishmentprobe_websocket_connection_duration_seconds- Time to establish WebSocket connection
The exporter implements a simple HTTP server with two main endpoints:
/metrics- Standard Prometheus metrics endpoint for the exporter itself/probe- Endpoint that accepts atargetparameter, probes the specified WebSocket URL, and returns metrics about the connection
The probe process:
- Establishes a WebSocket connection to the target
- Measures connection time
- Closes the connection
- Returns metrics about the connection attempt
- Connection Handling: Uses the Gorilla WebSocket library to establish connections
- Prometheus Integration: Uses the Prometheus client library to expose metrics
- VMProbe Compatibility: Follows the same pattern as the blackbox exporter
# Clone the repository
git clone https://github.com/naviat/blockchain-websocket-exporter.git
cd blockchain-websocket-exporter
# Build the Docker image
docker build -t naviat/blockchain-websocket-exporter:latest .For local testing with a kind Kubernetes cluster, see the LOCAL-KIND.md guide, which includes:
- Setting up a kind cluster
- Installing Victoria Metrics Operator
- Deploying the WebSocket exporter
- Configuring VMProbe for monitoring
- Setting up Grafana for visualization
- Apply the Kubernetes deployment:
kubectl apply -f websocket-exporter-deployment.yaml- Create a VMProbe to monitor your WebSocket endpoints:
kubectl apply -f vmprobe-config.yamlYou can test the exporter by sending a request to the probe endpoint:
curl "http://localhost:9095/probe?target=wss://your-blockchain-node.example.com/token"The response will include metrics about the probe:
# HELP probe_success Displays whether or not the probe was a success
# TYPE probe_success gauge
probe_success 1
# HELP probe_websocket_up Displays whether the WebSocket connection was successful
# TYPE probe_websocket_up gauge
probe_websocket_up 1
# HELP probe_websocket_connection_duration_seconds Duration of the WebSocket connection establishment
# TYPE probe_websocket_connection_duration_seconds gauge
probe_websocket_connection_duration_seconds 0.123
# HELP probe_duration_seconds Returns how long the probe took to complete in seconds
# TYPE probe_duration_seconds gauge
probe_duration_seconds 0.169
The exporter supports several command-line flags:
--web.listen-address- Address to listen on (default::9095)--web.telemetry-path- Path for exporter metrics (default:/metrics)--web.probe-path- Path for probe endpoint (default:/probe)--timeout- Probe timeout (default:10s)
Example:
./blockchain-websocket-exporter --timeout=5sThe VMProbe configuration specifies which endpoints to monitor:
apiVersion: operator.victoriametrics.com/v1beta1
kind: VMProbe
metadata:
name: websocket-connection-probe
namespace: victoria-metrics
spec:
jobName: websocket-connection-monitoring
vmProberSpec:
url: websocket-exporter.victoria-metrics.svc:9095
path: /probe
interval: 30s
targets:
staticConfig:
targets:
- wss://bsc-websocket-endpoint/token
- wss://eth-websocket-endpoint/token
- wss://polygon-websocket-endpoint/token
labels:
service: blockchain-nodesCreate alerts for WebSocket connection issues:
apiVersion: operator.victoriametrics.com/v1beta1
kind: VMRule
metadata:
name: websocket-connection-alerts
namespace: victoria-metrics
spec:
groups:
- name: websocket
rules:
- alert: WebSocketConnectionDown
expr: probe_websocket_up{job="websocket-connection-monitoring"} == 0
for: 2m
labels:
severity: critical
annotations:
summary: "WebSocket connection to {{ $labels.instance }} is down"
- alert: WebSocketHighConnectionLatency
expr: probe_websocket_connection_duration_seconds{job="websocket-connection-monitoring"} > 0.5
for: 5m
labels:
severity: warning
annotations:
summary: "WebSocket connection latency high for {{ $labels.instance }}"MIT