Add database queryTime metric

This commit is contained in:
calzoneman 2016-04-27 21:55:25 -07:00
parent 72bd3e4c98
commit 3b4800d045
3 changed files with 10 additions and 22 deletions

View File

@ -18,6 +18,7 @@
"cookie-parser": "^1.4.0",
"create-error": "^0.3.1",
"csrf": "^3.0.0",
"cytube-common": "git://github.com/CyTube/cytube-common",
"cytube-mediaquery": "git://github.com/CyTube/mediaquery",
"cytubefilters": "git://github.com/calzoneman/cytubefilters#67c7c69a",
"express": "^4.13.3",

View File

@ -4,20 +4,12 @@ var counterLog = new Logger.Logger(path.resolve(__dirname, '..', 'counters.log')
import os from 'os';
import io from 'socket.io';
import Socket from 'socket.io/lib/socket';
import * as Metrics from 'cytube-common/lib/metrics/metrics';
import { JSONFileMetricsReporter } from 'cytube-common/lib/metrics/jsonfilemetricsreporter';
var counters = {};
exports.add = function (counter, value) {
if (!value) {
value = 1;
}
if (!counters.hasOwnProperty(counter)) {
counters[counter] = value;
} else {
counters[counter] += value;
}
};
exports.add = Metrics.incCounter;
Socket.prototype._packet = Socket.prototype.packet;
Socket.prototype.packet = function () {
@ -34,14 +26,6 @@ function getConnectedSockets() {
}
}
setInterval(function () {
try {
counters['memory:rss'] = process.memoryUsage().rss / 1048576;
counters['load:1min'] = os.loadavg()[0];
counters['socket.io:count'] = getConnectedSockets();
counterLog.log(JSON.stringify(counters));
} catch (e) {
Logger.errlog.log(e.stack);
}
counters = {};
}, 60000);
const reporter = new JSONFileMetricsReporter('counters.log');
Metrics.setReporter(reporter);
Metrics.setReportInterval(60000);

View File

@ -6,6 +6,7 @@ var Config = require("./config");
var tables = require("./database/tables");
var net = require("net");
var util = require("./utilities");
import * as Metrics from 'cytube-common/lib/metrics/metrics';
var pool = null;
var global_ipbans = {};
@ -48,6 +49,7 @@ module.exports.init = function () {
* Execute a database query
*/
module.exports.query = function (query, sub, callback) {
const timer = Metrics.startTimer('db:queryTime');
// 2nd argument is optional
if (typeof sub === "function") {
callback = sub;
@ -75,6 +77,7 @@ module.exports.query = function (query, sub, callback) {
callback(null, res);
}
conn.release();
Metrics.stopTimer(timer);
}
if (sub) {