You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/packages/hydrooj/src/service/monitor.ts

41 lines
1.1 KiB
TypeScript

4 years ago
import cluster from 'cluster';
import * as db from './db';
import * as sysinfo from '../lib/sysinfo';
const coll = db.collection('status');
export async function update() {
4 years ago
const [mid, $set] = await sysinfo.update();
await coll.updateOne(
4 years ago
{ mid, type: 'server' },
{ $set: { ...$set, updateAt: new Date(), reqCount: global.Hydro.stat.reqCount } },
{ upsert: true },
);
global.Hydro.stat.reqCount = 0;
}
export function updateJudger(args) {
args.type = 'judger';
return coll.updateOne(
{ mid: args.mid, type: 'judger' },
{ $set: { ...args, updateAt: new Date() } },
{ upsert: true },
);
}
4 years ago
if (cluster.isMaster) {
global.Hydro.postInit.push(
async () => {
const info = await sysinfo.get();
await coll.updateOne(
{ mid: info.mid, type: 'server' },
{ $set: { ...info, updateAt: new Date(), type: 'server' } },
{ upsert: true },
);
setInterval(update, 60 * 1000);
},
);
}
global.Hydro.service.monitor = { update, updateJudger };