mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: judge count meter
This commit is contained in:
1 parent
d8bfbb0a22
commit
130fbcc2dd
3 files changed
+17
-8
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.39.24",
|
"version": "2.39.25",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { ObjectID } from 'mongodb';
|
import { ObjectID } from 'mongodb';
|
||||||
import tx2 from 'tx2';
|
|
||||||
import { JudgeResultBody, RecordDoc, TestCase } from '../interface';
|
import { JudgeResultBody, RecordDoc, TestCase } from '../interface';
|
||||||
import difficultyAlgorithm from '../lib/difficulty';
|
import difficultyAlgorithm from '../lib/difficulty';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
@@ -20,11 +19,6 @@ import {
|
|||||||
import { sleep } from '../utils';
|
import { sleep } from '../utils';
|
||||||
|
|
||||||
const logger = new Logger('judge');
|
const logger = new Logger('judge');
|
||||||
const judgeCount = tx2.meter({
|
|
||||||
name: 'judge/min',
|
|
||||||
samples: 60,
|
|
||||||
timeframe: 120,
|
|
||||||
});
|
|
||||||
|
|
||||||
export async function postJudge(rdoc: RecordDoc) {
|
export async function postJudge(rdoc: RecordDoc) {
|
||||||
if (typeof rdoc.input === 'string') return;
|
if (typeof rdoc.input === 'string') return;
|
||||||
@@ -86,7 +80,6 @@ export async function next(body: JudgeResultBody) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function end(body: JudgeResultBody) {
|
export async function end(body: JudgeResultBody) {
|
||||||
judgeCount.mark();
|
|
||||||
if (body.rid) body.rid = new ObjectID(body.rid);
|
if (body.rid) body.rid = new ObjectID(body.rid);
|
||||||
let rdoc = await record.get(body.rid);
|
let rdoc = await record.get(body.rid);
|
||||||
if (!rdoc) return;
|
if (!rdoc) return;
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import { dump } from 'js-yaml';
|
import { dump } from 'js-yaml';
|
||||||
import superagent from 'superagent';
|
import superagent from 'superagent';
|
||||||
|
import tx2 from 'tx2';
|
||||||
import type { StatusUpdate } from '@hydrooj/utils/lib/sysinfo';
|
import type { StatusUpdate } from '@hydrooj/utils/lib/sysinfo';
|
||||||
import * as sysinfo 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 { Logger } from '../logger';
|
||||||
import * as bus from './bus';
|
import * as bus from './bus';
|
||||||
import db from './db';
|
import db from './db';
|
||||||
@@ -96,6 +98,20 @@ if (process.env.NODE_APP_INSTANCE === '0') {
|
|||||||
feedback();
|
feedback();
|
||||||
setInterval(update, 60 * 1000);
|
setInterval(update, 60 * 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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user