Registry / observability / socket.io-prometheus

socket.io-prometheus

JSON →
library0.4.0jsnpmunverified

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-prometheus
INSTALL
IMPORT
SIG · SOCKET.IO-PROMETHE
S
socket.io-prometheus
observabilityjavascriptv0.4.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

socketIoPrometheus
✓ import ioMetrics from 'socket.io-prometheus';
✗ const ioMetrics = require('socket.io-prometheus');
While the README shows CommonJS `require`, modern Node.js applications should prefer ESM `import`. The package likely supports both due to its age and CommonJS roots.
register
✓ import { register } from 'prom-client';
✗ const promRegister = require('prom-client').register;
The `register` object from `prom-client` is essential for exposing metrics. It's a named import from the peer dependency.
contentType
✓ import { register } from 'prom-client'; /* then register.contentType */
✗ import { contentType } from 'prom-client';
The `contentType` is a property of the `register` object from `prom-client`, not a direct named export.

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.

import express from 'express'; import { createServer } from 'http'; import { Server } from 'socket.io'; import ioMetrics from 'socket.io-prometheus'; import { register } from 'prom-client'; const app = express(); const server = createServer(app); const io = new Server(server); // Start collecting socket.io metrics ioMetrics(io); // Expose metrics endpoint app.get('/metrics', (req, res) => { res.set('Content-Type', register.contentType); res.end(register.metrics()); }); const PORT = process.env.PORT || 3000; server.listen(PORT, () => { console.log(`Socket.IO server listening on port ${PORT}`); console.log(`Prometheus metrics available at http://localhost:${PORT}/metrics`); }); io.on('connection', (socket) => { console.log('A user connected'); socket.on('chat message', (msg) => { console.log('message: ' + msg); io.emit('chat message', msg); }); socket.on('disconnect', () => { console.log('User disconnected'); }); });
Debug
Known issues
gotchaThis package has a peer dependency on `prom-client` version `>=10 <16`. Ensure you install a compatible version of `prom-client` in your project, or the module might not function correctly or lead to dependency resolution issues.
fix
Install `prom-client` explicitly: `npm install prom-client@^15.0.0` (or another compatible version).
affects: >=0.4.0
gotchaThe `socket.io-prometheus` module only exposes the raw metrics. You are responsible for setting up an HTTP endpoint (e.g., using Express) to expose these metrics at a path (e.g., `/metrics`) that Prometheus can scrape.
fix
Implement an HTTP GET route that calls `res.set('Content-Type', register.contentType)` and `res.end(register.metrics())`.
affects: >=0.1.0
gotchaMetrics are prefixed with `socket_io_`. When configuring Prometheus scraping rules or dashboards, remember to use this prefix for all collected metrics (e.g., `socket_io_connected`, `socket_io_connect_total`).
fix
Adjust Prometheus queries and dashboard configurations to include the `socket_io_` prefix for all metrics from this collector.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'prom-client'
`prom-client` is a peer dependency and was not installed in the project.
fix
Install `prom-client` manually: `npm install prom-client` (or `yarn add prom-client`). Ensure the version is compatible, e.g., `>=10 <16`.
TypeError: Cannot read properties of undefined (reading 'contentType')
The `register` object from `prom-client` was not correctly imported or is undefined when attempting to access `register.contentType` or `register.metrics()`.
fix
Ensure `import { register } from 'prom-client';` (or `const { register } = require('prom-client');`) is correctly placed and `prom-client` is installed.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
prom-clientrequiredRequired for registering and exposing Prometheus metrics. This is a peer dependency.
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
2
Resources
socket.io-prometheus — npm install socket.io-prometheus · libregistry