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/hydro/service/monitor.ts

29 lines
758 B
TypeScript

import * as db from './db';
import * as sysinfo from '../lib/sysinfo';
const coll = db.collection('status');
async function update() {
const [mid, $set] = await sysinfo.update();
await coll.updateOne(
{ mid, type: 'server' },
{ $set: { ...$set, updateAt: new Date(), reqCount: global.Hydro.stat.reqCount } },
{ upsert: true },
);
global.Hydro.stat.reqCount = 0;
}
async function postInit() {
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 = { postInit };
export default { postInit };