core: export metrics with tx2

pull/210/head
undefined 3 years ago
parent 14df7d7a05
commit 7f25778671

@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.35.0",
"version": "2.35.1",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
@ -41,7 +41,8 @@
"serialize-javascript": "^6.0.0",
"sockjs": "^0.3.21",
"source-map-support": "^0.5.20",
"superagent": "^6.1.0"
"superagent": "^6.1.0",
"tx2": "^1.0.4"
},
"devDependencies": {
"@types/adm-zip": "^0.4.34",

@ -34,16 +34,17 @@ export function addon(addonPath: string, prepend = false) {
global.publicDirs[prepend ? 'push' : 'unshift'](publicPath);
const targets = fs.readdirSync(publicPath);
for (const target of targets) {
if (global.ui.manifest[target] && !prepend) {
global.ui.manifest[target] = publicPath;
} else if (!global.staticFiles[target]) {
global.ui.manifest[target] = publicPath;
if (global.Hydro.ui.manifest[target] && !prepend) {
global.Hydro.ui.manifest[target] = publicPath;
} else if (!global.Hydro.ui.manifest[target]) {
global.Hydro.ui.manifest[target] = publicPath;
}
}
}
global.addons[prepend ? 'unshift' : 'push'](modulePath);
} catch (e) {
logger.error(`Addon not found: ${addonPath}`);
logger.error(e);
}
} else logger.error(`Addon not found: ${addonPath}`);
}

@ -16,6 +16,7 @@ import {
import moment from 'moment-timezone';
import { ObjectID } from 'mongodb';
import sockjs from 'sockjs';
import tx2 from 'tx2';
import { parseMemoryMB } from '@hydrooj/utils/lib/utils';
import {
BlacklistedError, CsrfTokenError, HydroError,
@ -39,6 +40,12 @@ import * as bus from './bus';
const argv = cac().parse();
const logger = new Logger('server');
const reqCount = tx2.meter({
name: 'req/sec',
samples: 1,
timeframe: 60,
});
const connCount = tx2.counter({ name: 'connections' });
export const app = new Koa();
export const server = http.createServer(app.callback());
export const router = new Router();
@ -664,6 +671,7 @@ async function bail(name: string, ...args: any[]) {
}
async function handle(ctx, HandlerClass, checker) {
reqCount.mark();
const args = {
domainId: 'system', ...ctx.params, ...ctx.query, ...ctx.request.body, __start: Date.now(),
};
@ -862,9 +870,11 @@ export function Connection(
h.message(JSON.parse(data));
});
}
connCount.inc();
conn.on('close', async () => {
if (h.cleanup) await h.cleanup(args);
if (h.finish) await h.finish(args);
connCount.dec();
});
} catch (e) {
logger.warn('%o', e);

@ -30,9 +30,9 @@ declare module 'hydrooj/src/interface' {
const cache = {};
const coll = db.collection('cache');
const pages = Object.keys(global.ui.manifest)
const pages = Object.keys(global.Hydro.ui.manifest)
.filter((file) => file.endsWith('.page.js'))
.map((i) => readFileSync(join(global.ui.manifest[i], i), 'utf-8'));
.map((i) => readFileSync(join(global.Hydro.ui.manifest[i], i), 'utf-8'));
async function constant(args: ConstantArgs) {
// CompileLangs

@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.21.0",
"version": "4.21.1",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",

Loading…
Cancel
Save