diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2020-01-30 04:37:25 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-30 04:37:25 +0900 |
| commit | f6154dc0af1a0d65819e87240f4385f9573095cb (patch) | |
| tree | 699a5ca07d6727b7f8497d4769f25d6d62f94b5a /src/daemons | |
| parent | Add Event activity-type support (#5785) (diff) | |
| download | misskey-f6154dc0af1a0d65819e87240f4385f9573095cb.tar.gz misskey-f6154dc0af1a0d65819e87240f4385f9573095cb.tar.bz2 misskey-f6154dc0af1a0d65819e87240f4385f9573095cb.zip | |
v12 (#5712)
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com>
Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>
Diffstat (limited to 'src/daemons')
| -rw-r--r-- | src/daemons/notes-stats-child.ts | 28 | ||||
| -rw-r--r-- | src/daemons/notes-stats.ts | 26 | ||||
| -rw-r--r-- | src/daemons/queue-stats.ts | 35 | ||||
| -rw-r--r-- | src/daemons/server-stats.ts | 57 |
4 files changed, 37 insertions, 109 deletions
diff --git a/src/daemons/notes-stats-child.ts b/src/daemons/notes-stats-child.ts deleted file mode 100644 index b60f5badfd..0000000000 --- a/src/daemons/notes-stats-child.ts +++ /dev/null @@ -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); -}); diff --git a/src/daemons/notes-stats.ts b/src/daemons/notes-stats.ts deleted file mode 100644 index bddb54cfa5..0000000000 --- a/src/daemons/notes-stats.ts +++ /dev/null @@ -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); - }); - -} diff --git a/src/daemons/queue-stats.ts b/src/daemons/queue-stats.ts index e560354c74..288e855ae9 100644 --- a/src/daemons/queue-stats.ts +++ b/src/daemons/queue-stats.ts @@ -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(); diff --git a/src/daemons/server-stats.ts b/src/daemons/server-stats.ts index ee62c32d7e..88df421ba0 100644 --- a/src/daemons/server-stats.ts +++ b/src/daemons/server-stats.ts @@ -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; +} + +// NETWORK STAT +async function net() { + const iface = await si.networkInterfaceDefault(); + const data = await si.networkStats(iface); + return data[0]; } -// TOTAL MEMORY STAT -async function totalMem() { - const data = await sysUtils.mem(); - return data.total; +// FS STAT +async function fs() { + const data = await si.disksIO().catch(() => ({ rIO_sec: 0, wIO_sec: 0 })); + return data; } |