mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: remove builtin tx2 module (replace with prom-client plugin)
This commit is contained in:
1 parent
35b0463173
commit
0562661fb4
4 files changed
+1
-29
No files matched your search
@@ -47,8 +47,7 @@
|
||||
"semver": "^7.3.7",
|
||||
"serialize-javascript": "^6.0.0",
|
||||
"superagent": "^8.0.0",
|
||||
"thirty-two": "^1.0.2",
|
||||
"tx2": "^1.0.5"
|
||||
"thirty-two": "^1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/adm-zip": "^0.4.34",
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import crypto from 'crypto';
|
||||
import { dump } from 'js-yaml';
|
||||
import superagent from 'superagent';
|
||||
import tx2 from 'tx2';
|
||||
import type { StatusUpdate } from '@hydrooj/utils/lib/sysinfo';
|
||||
import * as sysinfo from '@hydrooj/utils/lib/sysinfo';
|
||||
import { Time } from '@hydrooj/utils/lib/utils';
|
||||
import { Logger } from '../logger';
|
||||
import * as bus from './bus';
|
||||
import db from './db';
|
||||
@@ -108,20 +106,6 @@ if (process.env.NODE_APP_INSTANCE === '0') {
|
||||
feedback();
|
||||
setInterval(update, 1800 * 1000);
|
||||
});
|
||||
const taskColl = db.collection('task');
|
||||
let taskCount = await taskColl.find().count();
|
||||
const recordColl = db.collection('record');
|
||||
let recordCount = await recordColl.find({
|
||||
_id: { $gte: Time.getObjectID(new Date(Date.now() - 60 * 1000)) },
|
||||
}).count();
|
||||
tx2.metric('task', () => taskCount);
|
||||
tx2.metric('submission', () => recordCount);
|
||||
setInterval(() => {
|
||||
taskColl.find().count().then((c) => { taskCount = c; });
|
||||
recordColl.find({
|
||||
_id: { $gte: Time.getObjectID(new Date(Date.now() - 60 * 1000)) },
|
||||
}).count().then((c) => { recordCount = c; });
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,10 @@ import { IncomingMessage } from 'http';
|
||||
import KoaRouter from 'koa-router';
|
||||
import parseUrl from 'parseurl';
|
||||
import { pathToRegexp } from 'path-to-regexp';
|
||||
import tx2 from 'tx2';
|
||||
import type WebSocket from 'ws';
|
||||
import type { KoaContext } from './server';
|
||||
|
||||
type WebSocketCallback = (socket: WebSocket, request: IncomingMessage, ctx: KoaContext) => void;
|
||||
const connCount = tx2.counter({ name: 'connections' });
|
||||
|
||||
export class WebSocketLayer {
|
||||
clients = new Set<WebSocket>();
|
||||
@@ -20,9 +18,7 @@ export class WebSocketLayer {
|
||||
accept(socket: WebSocket, request: IncomingMessage, ctx: KoaContext) {
|
||||
if (!this.regexp.test(parseUrl(request).pathname)) return false;
|
||||
this.clients.add(socket);
|
||||
connCount.inc();
|
||||
socket.on('close', () => {
|
||||
connCount.dec();
|
||||
this.clients.delete(socket);
|
||||
});
|
||||
this.callback?.(socket, request, ctx);
|
||||
|
||||
@@ -6,7 +6,6 @@ import Compress from 'koa-compress';
|
||||
import proxy from 'koa-proxies';
|
||||
import cache from 'koa-static-cache';
|
||||
import { filter } from 'lodash';
|
||||
import tx2 from 'tx2';
|
||||
import WebSocket from 'ws';
|
||||
import { parseMemoryMB } from '@hydrooj/utils/lib/utils';
|
||||
import {
|
||||
@@ -81,11 +80,6 @@ export interface KoaContext extends Koa.Context {
|
||||
|
||||
const argv = cac().parse();
|
||||
const logger = new Logger('server');
|
||||
const reqCount = tx2.meter({
|
||||
name: 'req/sec',
|
||||
samples: 1,
|
||||
timeframe: 60,
|
||||
});
|
||||
export const app = new Koa<Koa.DefaultState, KoaContext>({
|
||||
keys: system.get('server.keys'),
|
||||
});
|
||||
@@ -270,7 +264,6 @@ async function bail(name: string, ...args: any[]) {
|
||||
}
|
||||
|
||||
async function handle(ctx: KoaContext, HandlerClass, checker) {
|
||||
reqCount.mark();
|
||||
const {
|
||||
args, request, response, user, domain, UiContext,
|
||||
} = ctx.HydroContext;
|
||||
|
||||
Reference in new issue
Block a user