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.
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
4 years ago
|
import cluster from 'cluster';
|
||
4 years ago
|
import * as db from './db';
|
||
|
import * as sysinfo from '../lib/sysinfo';
|
||
4 years ago
|
|
||
|
const coll = db.collection('status');
|
||
|
|
||
4 years ago
|
export async function update() {
|
||
4 years ago
|
const [mid, $set] = await sysinfo.update();
|
||
4 years ago
|
await coll.updateOne(
|
||
4 years ago
|
{ mid, type: 'server' },
|
||
4 years ago
|
{ $set: { ...$set, updateAt: new Date(), reqCount: global.Hydro.stat.reqCount } },
|
||
4 years ago
|
{ upsert: true },
|
||
|
);
|
||
4 years ago
|
global.Hydro.stat.reqCount = 0;
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
export function updateJudger(args) {
|
||
|
args.type = 'judger';
|
||
|
return coll.updateOne(
|
||
|
{ mid: args.mid, type: 'judger' },
|
||
|
{ $set: args },
|
||
|
{ 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);
|
||
|
},
|
||
|
);
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
global.Hydro.service.monitor = { update, updateJudger };
|