socket.io-prometheus-metrics

Socket.IO prometheus metrics exporter written in typescript

Showing:

Popularity

Downloads/wk

288

GitHub Stars

25

Maintenance

Last Commit

1yr ago

Contributors

6

Package

Dependencies

3

Size (min+gzip)

238.2KB

License

Apache-2.0

Type Definitions

Built-In

Tree-Shakeable

No?

Categories

Readme

socket.io-prometheus-metrics

Exposes a metrics endpoint for prometheus to collect data about socket.io.

Installation

npm install socket.io-prometheus-metrics
# or
yarn add socket.io-prometheus-metrics

Usage

Basic usage

import * as http from 'http';
import * as io from 'socket.io';
import * as prometheus from 'socket.io-prometheus-metrics';

const server = http.createServer();
const io = io(server);

prometheus.metrics(io);

server.listen(3000);

Metrics is then available at localhost:9090/metrics.

Prometheus default metrics can also be enabled by setting the collectDefaultMetrics option to true

prometheus.metrics(io, {
    collectDefaultMetrics: true
});

If you wish to serve the metrics yourself the createServer options can be set to false and metrics can be collected from the register

const ioMetrics = prometheus.metrics(io, {
    createServer: false
});

const metrics = ioMetrics.register.metrics();

Options

OptionDefaultDescription
path"/metrics"Metrics path
port9090Metrics port
createServertrueAuto create http server
collectDefaultMetricsfalseCollect prometheus default metrics
checkForNewNamespacestrueCollect metrics for namespaces that will be added at runtime

Socket.io metrics

all metrics have socket_io_ prefix in their names.

NameHelpLabels
socket_io_connectedNumber of currently connected sockets
socket_io_connect_totalTotal count of socket.io connection requestsnamespace
socket_io_disconnect_totalTotal count of socket.io disconnectionsnamespace
socket_io_errors_totalTotal count of socket.io errorsnamespace
socket_io_events_received_totalTotal count of socket.io received eventsevent, namespace
socket_io_events_sent_totalTotal count of socket.io sent eventsevent, namespace
socket_io_receive_bytesTotal socket.io bytes receivedevent, namespace
socket_io_transmit_bytesTotal socket.io bytes transmittedevent, namespace

Prometheus default metrics

available if collectDefaultMetrics is set to true

More information here and here.

Namespaces support

Default namespace has label value of '/'.

By default library checks io.nsps variable for new namespaces to collect metrics from. This check occurs every 2 seconds.

You can disable this functionality by providing checkForNewNamespaces option with false value. For example:

prometheus.metrics(io, {
    checkForNewNamespaces: false
});

With this functionality disabled, library will only collect metrics from namespaces that were available at the moment of call to prometheus.metrics(io, ...), default namespace is included.

More information about socket.io namespaces here.

License

Licensed under the Apache 2.0 License. See the LICENSE file for details.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100