mirror of https://github.com/calzoneman/sync.git
Instrument some more metrics with prometheus
This commit is contained in:
parent
6043647cb7
commit
cb6cfc8455
|
@ -2,7 +2,7 @@
|
||||||
"author": "Calvin Montgomery",
|
"author": "Calvin Montgomery",
|
||||||
"name": "CyTube",
|
"name": "CyTube",
|
||||||
"description": "Online media synchronizer and chat",
|
"description": "Online media synchronizer and chat",
|
||||||
"version": "3.44.0",
|
"version": "3.44.1",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "http://github.com/calzoneman/sync"
|
"url": "http://github.com/calzoneman/sync"
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,6 +7,7 @@ var Flags = require("../flags");
|
||||||
var url = require("url");
|
var url = require("url");
|
||||||
var counters = require("../counters");
|
var counters = require("../counters");
|
||||||
import { transformImgTags } from '../camo';
|
import { transformImgTags } from '../camo';
|
||||||
|
import { Counter } from 'prom-client';
|
||||||
|
|
||||||
const SHADOW_TAG = "[shadow]";
|
const SHADOW_TAG = "[shadow]";
|
||||||
const LINK = /(\w+:\/\/(?:[^:\/\[\]\s]+|\[[0-9a-f:]+\])(?::\d+)?(?:\/[^\/\s]*)*)/ig;
|
const LINK = /(\w+:\/\/(?:[^:\/\[\]\s]+|\[[0-9a-f:]+\])(?::\d+)?(?:\/[^\/\s]*)*)/ig;
|
||||||
|
@ -149,9 +150,14 @@ ChatModule.prototype.restrictNewAccount = function restrictNewAccount(user, data
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const chatIncomingCount = new Counter({
|
||||||
|
name: 'cytube_chat_incoming_count',
|
||||||
|
help: 'Number of incoming chatMsg frames'
|
||||||
|
});
|
||||||
ChatModule.prototype.handleChatMsg = function (user, data) {
|
ChatModule.prototype.handleChatMsg = function (user, data) {
|
||||||
var self = this;
|
var self = this;
|
||||||
counters.add("chat:incoming");
|
counters.add("chat:incoming");
|
||||||
|
chatIncomingCount.inc();
|
||||||
|
|
||||||
if (!this.channel || !this.channel.modules.permissions.canChat(user)) {
|
if (!this.channel || !this.channel.modules.permissions.canChat(user)) {
|
||||||
return;
|
return;
|
||||||
|
@ -281,6 +287,10 @@ ChatModule.prototype.handlePm = function (user, data) {
|
||||||
user.socket.emit("pm", msgobj);
|
user.socket.emit("pm", msgobj);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const chatSentCount = new Counter({
|
||||||
|
name: 'cytube_chat_sent_count',
|
||||||
|
help: 'Number of broadcast chat messages'
|
||||||
|
});
|
||||||
ChatModule.prototype.processChatMsg = function (user, data) {
|
ChatModule.prototype.processChatMsg = function (user, data) {
|
||||||
if (data.msg.match(Config.get("link-domain-blacklist-regex"))) {
|
if (data.msg.match(Config.get("link-domain-blacklist-regex"))) {
|
||||||
this.channel.logger.log(user.displayip + " (" + user.getName() + ") was kicked for " +
|
this.channel.logger.log(user.displayip + " (" + user.getName() + ") was kicked for " +
|
||||||
|
@ -350,6 +360,7 @@ ChatModule.prototype.processChatMsg = function (user, data) {
|
||||||
}
|
}
|
||||||
this.sendMessage(msgobj);
|
this.sendMessage(msgobj);
|
||||||
counters.add("chat:sent");
|
counters.add("chat:sent");
|
||||||
|
chatSentCount.inc();
|
||||||
};
|
};
|
||||||
|
|
||||||
ChatModule.prototype.formatMessage = function (username, data) {
|
ChatModule.prototype.formatMessage = function (username, data) {
|
||||||
|
|
|
@ -7,8 +7,17 @@ var util = require("./utilities");
|
||||||
import * as Metrics from './metrics/metrics';
|
import * as Metrics from './metrics/metrics';
|
||||||
import knex from 'knex';
|
import knex from 'knex';
|
||||||
import { GlobalBanDB } from './db/globalban';
|
import { GlobalBanDB } from './db/globalban';
|
||||||
|
import { Summary, Counter } from 'prom-client';
|
||||||
|
|
||||||
const LOGGER = require('@calzoneman/jsli')('database');
|
const LOGGER = require('@calzoneman/jsli')('database');
|
||||||
|
const queryLatency = new Summary({
|
||||||
|
name: 'cytube_db_query_latency',
|
||||||
|
help: 'DB query latency (including time spent acquiring connections)'
|
||||||
|
});
|
||||||
|
const queryCount = new Counter({
|
||||||
|
name: 'cytube_db_query_count',
|
||||||
|
help: 'DB query count'
|
||||||
|
});
|
||||||
|
|
||||||
let db = null;
|
let db = null;
|
||||||
let globalBanDB = null;
|
let globalBanDB = null;
|
||||||
|
@ -41,8 +50,11 @@ class Database {
|
||||||
|
|
||||||
runTransaction(fn) {
|
runTransaction(fn) {
|
||||||
const timer = Metrics.startTimer('db:queryTime');
|
const timer = Metrics.startTimer('db:queryTime');
|
||||||
|
const end = queryLatency.startTimer();
|
||||||
return this.knex.transaction(fn).finally(() => {
|
return this.knex.transaction(fn).finally(() => {
|
||||||
|
end();
|
||||||
Metrics.stopTimer(timer);
|
Metrics.stopTimer(timer);
|
||||||
|
queryCount.inc();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,14 @@ var Streamable = require("cytube-mediaquery/lib/provider/streamable");
|
||||||
var GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive");
|
var GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive");
|
||||||
var TwitchVOD = require("cytube-mediaquery/lib/provider/twitch-vod");
|
var TwitchVOD = require("cytube-mediaquery/lib/provider/twitch-vod");
|
||||||
var TwitchClip = require("cytube-mediaquery/lib/provider/twitch-clip");
|
var TwitchClip = require("cytube-mediaquery/lib/provider/twitch-clip");
|
||||||
|
import { Counter } from 'prom-client';
|
||||||
|
|
||||||
const LOGGER = require('@calzoneman/jsli')('get-info');
|
const LOGGER = require('@calzoneman/jsli')('get-info');
|
||||||
|
const lookupCounter = new Counter({
|
||||||
|
name: 'cytube_media_lookup_count',
|
||||||
|
help: 'Count of media lookups',
|
||||||
|
labelNames: ['shortCode']
|
||||||
|
});
|
||||||
|
|
||||||
var urlRetrieve = function (transport, options, callback) {
|
var urlRetrieve = function (transport, options, callback) {
|
||||||
var req = transport.request(options, function (res) {
|
var req = transport.request(options, function (res) {
|
||||||
|
@ -541,6 +547,7 @@ module.exports = {
|
||||||
getMedia: function (id, type, callback) {
|
getMedia: function (id, type, callback) {
|
||||||
if(type in this.Getters) {
|
if(type in this.Getters) {
|
||||||
LOGGER.info("Looking up %s:%s", type, id);
|
LOGGER.info("Looking up %s:%s", type, id);
|
||||||
|
lookupCounter.labels(type).inc();
|
||||||
this.Getters[type](id, callback);
|
this.Getters[type](id, callback);
|
||||||
} else {
|
} else {
|
||||||
callback("Unknown media type '" + type + "'", null);
|
callback("Unknown media type '" + type + "'", null);
|
||||||
|
|
|
@ -169,6 +169,7 @@ class IOServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
initSocketIO() {
|
initSocketIO() {
|
||||||
|
patchSocketMetrics();
|
||||||
patchTypecheckedFunctions();
|
patchTypecheckedFunctions();
|
||||||
|
|
||||||
const io = this.io = sio.instance = sio();
|
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 */
|
/* TODO: remove this crap */
|
||||||
function patchTypecheckedFunctions() {
|
function patchTypecheckedFunctions() {
|
||||||
Socket.prototype.typecheckedOn = function typecheckedOn(msg, template, cb) {
|
Socket.prototype.typecheckedOn = function typecheckedOn(msg, template, cb) {
|
||||||
|
|
Loading…
Reference in New Issue