mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: data feedback system
This commit is contained in:
1 parent
83cc85492d
commit
1817341eee
7 files changed
+54
-5
No files matched your search
@@ -1,11 +1,56 @@
|
||||
import cluster from 'cluster';
|
||||
import crypto from 'crypto';
|
||||
import axios from 'axios';
|
||||
import { safeDump } from 'js-yaml';
|
||||
import * as db from './db';
|
||||
import * as bus from './bus';
|
||||
import * as sysinfo from '../lib/sysinfo';
|
||||
|
||||
const coll = db.collection('status');
|
||||
|
||||
function crypt(str: string) {
|
||||
const cipher = crypto.createCipheriv('des-ecb', 'hydro-oj', '');
|
||||
let encrypted = cipher.update(str, 'utf8', 'hex');
|
||||
encrypted += cipher.final('hex');
|
||||
return encrypted;
|
||||
}
|
||||
|
||||
export async function feedback() {
|
||||
const {
|
||||
system, domain, document, user, record,
|
||||
} = global.Hydro.model;
|
||||
const version = require('hydrooj/package.json').version;
|
||||
const [mid, , inf] = await sysinfo.update();
|
||||
const [installid, name, url] = system.getMany([
|
||||
'installid', 'server.name', 'server.url',
|
||||
]);
|
||||
const [domainCount, userCount, problemCount, discussionCount, recordCount] = await Promise.all([
|
||||
domain.getMulti().count(),
|
||||
user.getMulti().count(),
|
||||
document.coll.find({ docType: document.TYPE_PROBLEM }).count(),
|
||||
document.coll.find({ docType: document.TYPE_DISCUSSION }).count(),
|
||||
record.coll.find().count(),
|
||||
]);
|
||||
const payload = crypt(safeDump({
|
||||
_id: installid + mid.toString(),
|
||||
version,
|
||||
name,
|
||||
url,
|
||||
domainCount,
|
||||
userCount,
|
||||
problemCount,
|
||||
discussionCount,
|
||||
recordCount,
|
||||
addons: global.addons,
|
||||
memory: inf.memory,
|
||||
osinfo: inf.osinfo,
|
||||
flags: inf.flags,
|
||||
}));
|
||||
axios.post('https://feedback.undefined.moe/', { payload });
|
||||
}
|
||||
|
||||
export async function update() {
|
||||
await feedback();
|
||||
const [mid, $set] = await sysinfo.update();
|
||||
$set.updateAt = new Date();
|
||||
$set.reqCount = global.Hydro.stat.reqCount;
|
||||
@@ -36,8 +81,9 @@ if (cluster.isMaster) {
|
||||
{ $set: { ...info, updateAt: new Date(), type: 'server' } },
|
||||
{ upsert: true },
|
||||
);
|
||||
await feedback();
|
||||
setInterval(update, 60 * 1000);
|
||||
});
|
||||
}
|
||||
|
||||
global.Hydro.service.monitor = { update, updateJudger };
|
||||
global.Hydro.service.monitor = { feedback, update, updateJudger };
|
||||
Reference in new issue
Block a user