v12 (#5712)
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
import { MoreThanOrEqual, getRepository } from 'typeorm';
|
||||
import { Note } from '../models/entities/note';
|
||||
import { initDb } from '../db/postgre';
|
||||
|
||||
const interval = 5000;
|
||||
|
||||
initDb().then(() => {
|
||||
const Notes = getRepository(Note);
|
||||
|
||||
async function tick() {
|
||||
const [all, local] = await Promise.all([Notes.count({
|
||||
createdAt: MoreThanOrEqual(new Date(Date.now() - interval))
|
||||
}), Notes.count({
|
||||
createdAt: MoreThanOrEqual(new Date(Date.now() - interval)),
|
||||
userHost: null
|
||||
})]);
|
||||
|
||||
const stats = {
|
||||
all, local
|
||||
};
|
||||
|
||||
process.send!(stats);
|
||||
}
|
||||
|
||||
tick();
|
||||
|
||||
setInterval(tick, interval);
|
||||
});
|
@@ -1,26 +0,0 @@
|
||||
import * as childProcess from 'child_process';
|
||||
import * as Deque from 'double-ended-queue';
|
||||
import Xev from 'xev';
|
||||
|
||||
const ev = new Xev();
|
||||
|
||||
export default function() {
|
||||
const log = new Deque<any>();
|
||||
|
||||
const p = childProcess.fork(__dirname + '/notes-stats-child.js');
|
||||
|
||||
p.on('message', stats => {
|
||||
ev.emit('notesStats', stats);
|
||||
log.push(stats);
|
||||
if (log.length > 100) log.shift();
|
||||
});
|
||||
|
||||
ev.on('requestNotesStatsLog', id => {
|
||||
ev.emit(`notesStatsLog:${id}`, log.toArray());
|
||||
});
|
||||
|
||||
process.on('exit', code => {
|
||||
process.kill(p.pid);
|
||||
});
|
||||
|
||||
}
|
@@ -1,25 +1,22 @@
|
||||
import * as Deque from 'double-ended-queue';
|
||||
import Xev from 'xev';
|
||||
import { deliverQueue, inboxQueue, dbQueue, objectStorageQueue } from '../queue';
|
||||
import { deliverQueue, inboxQueue } from '../queue';
|
||||
|
||||
const ev = new Xev();
|
||||
|
||||
const interval = 3000;
|
||||
const interval = 10000;
|
||||
|
||||
/**
|
||||
* Report queue stats regularly
|
||||
*/
|
||||
export default function() {
|
||||
const log = new Deque<any>();
|
||||
const log = [] as any[];
|
||||
|
||||
ev.on('requestQueueStatsLog', x => {
|
||||
ev.emit(`queueStatsLog:${x.id}`, log.toArray().slice(0, x.length || 50));
|
||||
ev.emit(`queueStatsLog:${x.id}`, log.slice(0, x.length || 50));
|
||||
});
|
||||
|
||||
let activeDeliverJobs = 0;
|
||||
let activeInboxJobs = 0;
|
||||
let activeDbJobs = 0;
|
||||
let activeObjectStorageJobs = 0;
|
||||
|
||||
deliverQueue.on('global:active', () => {
|
||||
activeDeliverJobs++;
|
||||
@@ -29,19 +26,9 @@ export default function() {
|
||||
activeInboxJobs++;
|
||||
});
|
||||
|
||||
dbQueue.on('global:active', () => {
|
||||
activeDbJobs++;
|
||||
});
|
||||
|
||||
objectStorageQueue.on('global:active', () => {
|
||||
activeObjectStorageJobs++;
|
||||
});
|
||||
|
||||
async function tick() {
|
||||
const deliverJobCounts = await deliverQueue.getJobCounts();
|
||||
const inboxJobCounts = await inboxQueue.getJobCounts();
|
||||
const dbJobCounts = await dbQueue.getJobCounts();
|
||||
const objectStorageJobCounts = await objectStorageQueue.getJobCounts();
|
||||
|
||||
const stats = {
|
||||
deliver: {
|
||||
@@ -56,18 +43,6 @@ export default function() {
|
||||
waiting: inboxJobCounts.waiting,
|
||||
delayed: inboxJobCounts.delayed
|
||||
},
|
||||
db: {
|
||||
activeSincePrevTick: activeDbJobs,
|
||||
active: dbJobCounts.active,
|
||||
waiting: dbJobCounts.waiting,
|
||||
delayed: dbJobCounts.delayed
|
||||
},
|
||||
objectStorage: {
|
||||
activeSincePrevTick: activeObjectStorageJobs,
|
||||
active: objectStorageJobCounts.active,
|
||||
waiting: objectStorageJobCounts.waiting,
|
||||
delayed: objectStorageJobCounts.delayed
|
||||
},
|
||||
};
|
||||
|
||||
ev.emit('queueStats', stats);
|
||||
@@ -77,8 +52,6 @@ export default function() {
|
||||
|
||||
activeDeliverJobs = 0;
|
||||
activeInboxJobs = 0;
|
||||
activeDbJobs = 0;
|
||||
activeObjectStorageJobs = 0;
|
||||
}
|
||||
|
||||
tick();
|
||||
|
@@ -1,39 +1,41 @@
|
||||
import * as os from 'os';
|
||||
import * as sysUtils from 'systeminformation';
|
||||
import * as diskusage from 'diskusage';
|
||||
import * as Deque from 'double-ended-queue';
|
||||
import * as si from 'systeminformation';
|
||||
import Xev from 'xev';
|
||||
import * as osUtils from 'os-utils';
|
||||
|
||||
const ev = new Xev();
|
||||
|
||||
const interval = 1000;
|
||||
const interval = 2000;
|
||||
|
||||
/**
|
||||
* Report server stats regularly
|
||||
*/
|
||||
export default function() {
|
||||
const log = new Deque<any>();
|
||||
const log = [] as any[];
|
||||
|
||||
ev.on('requestServerStatsLog', x => {
|
||||
ev.emit(`serverStatsLog:${x.id}`, log.toArray().slice(0, x.length || 50));
|
||||
ev.emit(`serverStatsLog:${x.id}`, log.slice(0, x.length || 50));
|
||||
});
|
||||
|
||||
async function tick() {
|
||||
const cpu = await cpuUsage();
|
||||
const usedmem = await usedMem();
|
||||
const totalmem = await totalMem();
|
||||
const disk = await diskusage.check(os.platform() == 'win32' ? 'c:' : '/');
|
||||
const memStats = await mem();
|
||||
const netStats = await net();
|
||||
const fsStats = await fs();
|
||||
|
||||
const stats = {
|
||||
cpu_usage: cpu,
|
||||
cpu: cpu,
|
||||
mem: {
|
||||
total: totalmem,
|
||||
used: usedmem
|
||||
used: memStats.used,
|
||||
active: memStats.active,
|
||||
},
|
||||
disk,
|
||||
os_uptime: os.uptime(),
|
||||
process_uptime: process.uptime()
|
||||
net: {
|
||||
rx: Math.max(0, netStats.rx_sec),
|
||||
tx: Math.max(0, netStats.tx_sec),
|
||||
},
|
||||
fs: {
|
||||
r: Math.max(0, fsStats.rIO_sec),
|
||||
w: Math.max(0, fsStats.wIO_sec),
|
||||
}
|
||||
};
|
||||
ev.emit('serverStats', stats);
|
||||
log.unshift(stats);
|
||||
@@ -54,14 +56,21 @@ function cpuUsage() {
|
||||
});
|
||||
}
|
||||
|
||||
// MEMORY(excl buffer + cache) STAT
|
||||
async function usedMem() {
|
||||
const data = await sysUtils.mem();
|
||||
return data.active;
|
||||
// MEMORY STAT
|
||||
async function mem() {
|
||||
const data = await si.mem();
|
||||
return data;
|
||||
}
|
||||
|
||||
// TOTAL MEMORY STAT
|
||||
async function totalMem() {
|
||||
const data = await sysUtils.mem();
|
||||
return data.total;
|
||||
// NETWORK STAT
|
||||
async function net() {
|
||||
const iface = await si.networkInterfaceDefault();
|
||||
const data = await si.networkStats(iface);
|
||||
return data[0];
|
||||
}
|
||||
|
||||
// FS STAT
|
||||
async function fs() {
|
||||
const data = await si.disksIO().catch(() => ({ rIO_sec: 0, wIO_sec: 0 }));
|
||||
return data;
|
||||
}
|
||||
|
Reference in New Issue
Block a user