mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: export metrics with tx2
This commit is contained in:
1 parent
14df7d7a05
commit
7f25778671
5 files changed
+21
-9
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.35.0",
|
"version": "2.35.1",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
@@ -41,7 +41,8 @@
|
|||||||
"serialize-javascript": "^6.0.0",
|
"serialize-javascript": "^6.0.0",
|
||||||
"sockjs": "^0.3.21",
|
"sockjs": "^0.3.21",
|
||||||
"source-map-support": "^0.5.20",
|
"source-map-support": "^0.5.20",
|
||||||
"superagent": "^6.1.0"
|
"superagent": "^6.1.0",
|
||||||
|
"tx2": "^1.0.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/adm-zip": "^0.4.34",
|
"@types/adm-zip": "^0.4.34",
|
||||||
|
|||||||
@@ -34,16 +34,17 @@ export function addon(addonPath: string, prepend = false) {
|
|||||||
global.publicDirs[prepend ? 'push' : 'unshift'](publicPath);
|
global.publicDirs[prepend ? 'push' : 'unshift'](publicPath);
|
||||||
const targets = fs.readdirSync(publicPath);
|
const targets = fs.readdirSync(publicPath);
|
||||||
for (const target of targets) {
|
for (const target of targets) {
|
||||||
if (global.ui.manifest[target] && !prepend) {
|
if (global.Hydro.ui.manifest[target] && !prepend) {
|
||||||
global.ui.manifest[target] = publicPath;
|
global.Hydro.ui.manifest[target] = publicPath;
|
||||||
} else if (!global.staticFiles[target]) {
|
} else if (!global.Hydro.ui.manifest[target]) {
|
||||||
global.ui.manifest[target] = publicPath;
|
global.Hydro.ui.manifest[target] = publicPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
global.addons[prepend ? 'unshift' : 'push'](modulePath);
|
global.addons[prepend ? 'unshift' : 'push'](modulePath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`Addon not found: ${addonPath}`);
|
logger.error(`Addon not found: ${addonPath}`);
|
||||||
|
logger.error(e);
|
||||||
}
|
}
|
||||||
} else logger.error(`Addon not found: ${addonPath}`);
|
} else logger.error(`Addon not found: ${addonPath}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
import { ObjectID } from 'mongodb';
|
import { ObjectID } from 'mongodb';
|
||||||
import sockjs from 'sockjs';
|
import sockjs from 'sockjs';
|
||||||
|
import tx2 from 'tx2';
|
||||||
import { parseMemoryMB } from '@hydrooj/utils/lib/utils';
|
import { parseMemoryMB } from '@hydrooj/utils/lib/utils';
|
||||||
import {
|
import {
|
||||||
BlacklistedError, CsrfTokenError, HydroError,
|
BlacklistedError, CsrfTokenError, HydroError,
|
||||||
@@ -39,6 +40,12 @@ import * as bus from './bus';
|
|||||||
|
|
||||||
const argv = cac().parse();
|
const argv = cac().parse();
|
||||||
const logger = new Logger('server');
|
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 app = new Koa();
|
||||||
export const server = http.createServer(app.callback());
|
export const server = http.createServer(app.callback());
|
||||||
export const router = new Router();
|
export const router = new Router();
|
||||||
@@ -664,6 +671,7 @@ async function bail(name: string, ...args: any[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handle(ctx, HandlerClass, checker) {
|
async function handle(ctx, HandlerClass, checker) {
|
||||||
|
reqCount.mark();
|
||||||
const args = {
|
const args = {
|
||||||
domainId: 'system', ...ctx.params, ...ctx.query, ...ctx.request.body, __start: Date.now(),
|
domainId: 'system', ...ctx.params, ...ctx.query, ...ctx.request.body, __start: Date.now(),
|
||||||
};
|
};
|
||||||
@@ -862,9 +870,11 @@ export function Connection(
|
|||||||
h.message(JSON.parse(data));
|
h.message(JSON.parse(data));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
connCount.inc();
|
||||||
conn.on('close', async () => {
|
conn.on('close', async () => {
|
||||||
if (h.cleanup) await h.cleanup(args);
|
if (h.cleanup) await h.cleanup(args);
|
||||||
if (h.finish) await h.finish(args);
|
if (h.finish) await h.finish(args);
|
||||||
|
connCount.dec();
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warn('%o', e);
|
logger.warn('%o', e);
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ declare module 'hydrooj/src/interface' {
|
|||||||
|
|
||||||
const cache = {};
|
const cache = {};
|
||||||
const coll = db.collection('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'))
|
.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) {
|
async function constant(args: ConstantArgs) {
|
||||||
// CompileLangs
|
// CompileLangs
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.21.0",
|
"version": "4.21.1",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
Reference in new issue
Block a user