{"library":"socket.io-prometheus","title":"Socket.IO Prometheus Metrics","type":"library","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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install socket.io-prometheus"],"cli":null},"imports":["import ioMetrics from 'socket.io-prometheus';","import { register } from 'prom-client';","import { register } from 'prom-client'; /* then register.contentType */"],"auth":{"required":false,"env_vars":[]},"links":{"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},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}