socket.io-prometheus-metrics
Exposes a metrics endpoint for prometheus to collect data about socket.io
.
Installation
npm install socket.io-prometheus-metrics
Usage
Basic usage
;;; ;; prometheus.metricsio; server.listen3000;
Metrics is then available at localhost:9090/metrics
.
Prometheus default metrics can also be enabled by setting the collectDefaultMetrics
option to true
prometheus.metricsio, ;
If you wish to serve the metrics yourself the createServer
options can be set to false
and metrics can be collected from the register
; ;
Options
Option | Default | Description |
---|---|---|
path |
"/metrics" | Metrics path |
port |
9090 | Metrics port |
createServer |
true | Auto create http server |
collectDefaultMetrics |
false | Collect prometheus default metrics |
checkForNewNamespaces |
true | Collect metrics for namespaces that will be added at runtime |
Socket.io metrics
all metrics have
socket_io_
prefix in their names.
Name | Help | Labels |
---|---|---|
socket_io_connected |
Number of currently connected sockets | |
socket_io_connect_total |
Total count of socket.io connection requests | namespace |
socket_io_disconnect_total |
Total count of socket.io disconnections | namespace |
socket_io_errors_total |
Total count of socket.io errors | namespace |
socket_io_events_received_total |
Total count of socket.io recieved events | event , namespace |
socket_io_events_sent_total |
Total count of socket.io sent events | event , namespace |
socket_io_recieve_bytes |
Total socket.io bytes recieved | event , namespace |
socket_io_transmit_bytes |
Total socket.io bytes transmitted | event , namespace |
Prometheus default metrics
available if
collectDefaultMetrics
is set totrue
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.metricsio, ;
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.