socket.io-prometheus is a library designed to collect and expose Prometheus metrics from a Socket.IO server instance. It integrates directly with a `socket.io` server to monitor connection totals, disconnections, connected client counts, and event traffic (both sent and received) along with byte counts. The current stable version is 0.4.0, which appears to be under active maintenance rather than rapid feature development, with recent updates focused on package maintenance and CI matrix adjustments. A key differentiator is its direct, minimal integration specifically for Socket.IO, leveraging `prom-client` for metric registration and exposition, making it a straightforward solution for adding observability to Socket.IO applications within a Prometheus ecosystem.
npm install socket.io-prometheusVerified import paths — ran on the pinned version, not inferred.
This example initializes a Socket.IO server, attaches `socket.io-prometheus` to collect metrics, and exposes a `/metrics` endpoint for Prometheus to scrape. It also includes basic Socket.IO connection/disconnection and message handling to generate some metric data.
Install `prom-client` explicitly: `npm install prom-client@^15.0.0` (or another compatible version).
Implement an HTTP GET route that calls `res.set('Content-Type', register.contentType)` and `res.end(register.metrics())`.Adjust Prometheus queries and dashboard configurations to include the `socket_io_` prefix for all metrics from this collector.
Install `prom-client` manually: `npm install prom-client` (or `yarn add prom-client`). Ensure the version is compatible, e.g., `>=10 <16`.
Ensure `import { register } from 'prom-client';` (or `const { register } = require('prom-client');`) is correctly placed and `prom-client` is installed.