{"id":14032,"library":"socket.io-prometheus","title":"Socket.IO Prometheus Metrics","description":"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.","status":"active","version":"0.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/shamil/socket.io-prometheus","tags":["javascript","prometheus","socket.io"],"install":[{"cmd":"npm install socket.io-prometheus","lang":"bash","label":"npm"},{"cmd":"yarn add socket.io-prometheus","lang":"bash","label":"yarn"},{"cmd":"pnpm add socket.io-prometheus","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for registering and exposing Prometheus metrics. This is a peer dependency.","package":"prom-client","optional":false}],"imports":[{"note":"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.","wrong":"const ioMetrics = require('socket.io-prometheus');","symbol":"socketIoPrometheus","correct":"import ioMetrics from 'socket.io-prometheus';"},{"note":"The `register` object from `prom-client` is essential for exposing metrics. It's a named import from the peer dependency.","wrong":"const promRegister = require('prom-client').register;","symbol":"register","correct":"import { register } from 'prom-client';"},{"note":"The `contentType` is a property of the `register` object from `prom-client`, not a direct named export.","wrong":"import { contentType } from 'prom-client';","symbol":"contentType","correct":"import { register } from 'prom-client'; /* then register.contentType */"}],"quickstart":{"code":"import express from 'express';\nimport { createServer } from 'http';\nimport { Server } from 'socket.io';\nimport ioMetrics from 'socket.io-prometheus';\nimport { register } from 'prom-client';\n\nconst app = express();\nconst server = createServer(app);\nconst io = new Server(server);\n\n// Start collecting socket.io metrics\nioMetrics(io);\n\n// Expose metrics endpoint\napp.get('/metrics', (req, res) => {\n  res.set('Content-Type', register.contentType);\n  res.end(register.metrics());\n});\n\nconst PORT = process.env.PORT || 3000;\nserver.listen(PORT, () => {\n  console.log(`Socket.IO server listening on port ${PORT}`);\n  console.log(`Prometheus metrics available at http://localhost:${PORT}/metrics`);\n});\n\nio.on('connection', (socket) => {\n  console.log('A user connected');\n  socket.on('chat message', (msg) => {\n    console.log('message: ' + msg);\n    io.emit('chat message', msg);\n  });\n  socket.on('disconnect', () => {\n    console.log('User disconnected');\n  });\n});","lang":"typescript","description":"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."},"warnings":[{"fix":"Install `prom-client` explicitly: `npm install prom-client@^15.0.0` (or another compatible version).","message":"This 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.","severity":"gotcha","affected_versions":">=0.4.0"},{"fix":"Implement an HTTP GET route that calls `res.set('Content-Type', register.contentType)` and `res.end(register.metrics())`.","message":"The `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.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Adjust Prometheus queries and dashboard configurations to include the `socket_io_` prefix for all metrics from this collector.","message":"Metrics 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`).","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.4.0':52 'activ':58 'ad':102 'adjust':75 'along':43 'appear':54 'applic':106 'byte':45 'ci':73 'client':34,90 'collect':11 'connect':30,33 'count':35,46 'current':48 'design':9 'develop':64 'differenti':78 'direct':23,81 'disconnect':32 'ecosystem':110 'event':37 'expos':13 'exposit':95 'featur':63 'focus':68 'instanc':20 'integr':22,83 'javascript':111 'key':77 'leverag':87 'librari':8 'mainten':59,71 'make':96 'matrix':74 'metric':3,15,92 'minim':82 'monitor':29 'observ':103 'packag':70 'prom':89 'prom-client':88 'prometheus':2,5,14,109,112 'rapid':62 'rather':60 'receiv':42 'recent':66 'registr':93 'sent':40 'server':19,27 'socket.io':1,4,18,26,86,105,113 'solut':100 'specif':84 'stabl':49 'straightforward':99 'total':31 'traffic':38 'updat':67 'version':50 'within':107","created_at":"2026-04-20T01:57:34.334508+00:00","updated_at":"2026-04-20T01:57:34.334508+00:00","problems":[{"fix":"Install `prom-client` manually: `npm install prom-client` (or `yarn add prom-client`). Ensure the version is compatible, e.g., `>=10 <16`.","cause":"`prom-client` is a peer dependency and was not installed in the project.","error":"Error: Cannot find module 'prom-client'"},{"fix":"Ensure `import { register } from 'prom-client';` (or `const { register } = require('prom-client');`) is correctly placed and `prom-client` is installed.","cause":"The `register` object from `prom-client` was not correctly imported or is undefined when attempting to access `register.contentType` or `register.metrics()`.","error":"TypeError: Cannot read properties of undefined (reading 'contentType')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/shamil/socket.io-prometheus","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/socket.io-prometheus","openapi_spec":null,"status_page":null,"smithery":null,"categories":["observability","communication","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}