Instrument some more metrics with prometheus

This commit is contained in:
Calvin Montgomery 2017-08-02 21:24:44 -07:00
parent 6043647cb7
commit cb6cfc8455
5 changed files with 55 additions and 1 deletions

View file

@ -169,6 +169,7 @@ class IOServer {
}
initSocketIO() {
patchSocketMetrics();
patchTypecheckedFunctions();
const io = this.io = sio.instance = sio();
@ -194,6 +195,29 @@ class IOServer {
}
}
const incomingEventCount = new Counter({
name: 'cytube_socketio_incoming_events',
help: 'Number of received socket.io events from clients'
});
const outgoingPacketCount = new Counter({
name: 'cytube_socketio_outgoing_packets',
help: 'Number of outgoing socket.io packets to clients'
});
function patchSocketMetrics() {
const onevent = Socket.prototype.onevent;
const packet = Socket.prototype.packet;
Socket.prototype.onevent = function patchedOnevent() {
onevent.apply(this, arguments);
incomingEventCount.inc();
};
Socket.prototype.packet = function patchedPacket() {
packet.apply(this, arguments);
outgoingPacketCount.inc();
};
}
/* TODO: remove this crap */
function patchTypecheckedFunctions() {
Socket.prototype.typecheckedOn = function typecheckedOn(msg, template, cb) {