diff options
Diffstat (limited to 'src/daemons')
| -rw-r--r-- | src/daemons/hashtags-stats-child.ts | 60 | ||||
| -rw-r--r-- | src/daemons/hashtags-stats.ts | 20 | ||||
| -rw-r--r-- | src/daemons/notes-stats.ts | 2 | ||||
| -rw-r--r-- | src/daemons/server-stats.ts | 4 |
4 files changed, 3 insertions, 83 deletions
diff --git a/src/daemons/hashtags-stats-child.ts b/src/daemons/hashtags-stats-child.ts deleted file mode 100644 index 3f7f4d6e9e..0000000000 --- a/src/daemons/hashtags-stats-child.ts +++ /dev/null @@ -1,60 +0,0 @@ -import Note from '../models/note'; - -// 10分 -const interval = 1000 * 60 * 10; - -async function tick() { - const res = await Note.aggregate([{ - $match: { - createdAt: { - $gt: new Date(Date.now() - interval) - }, - tags: { - $exists: true, - $ne: [] - } - } - }, { - $unwind: '$tags' - }, { - $group: { - _id: '$tags', - count: { - $sum: 1 - } - } - }, { - $group: { - _id: null, - tags: { - $push: { - tag: '$_id', - count: '$count' - } - } - } - }, { - $project: { - _id: false, - tags: true - } - }]) as { - tags: Array<{ - tag: string; - count: number; - }> - }; - - const stats = res.tags - .sort((a, b) => a.count - b.count) - .map(tag => [tag.tag, tag.count]) - .slice(0, 10); - - console.log(stats); - - process.send(stats); -} - -tick(); - -setInterval(tick, interval); diff --git a/src/daemons/hashtags-stats.ts b/src/daemons/hashtags-stats.ts deleted file mode 100644 index 5ed028ac33..0000000000 --- a/src/daemons/hashtags-stats.ts +++ /dev/null @@ -1,20 +0,0 @@ -import * as childProcess from 'child_process'; -import Xev from 'xev'; - -const ev = new Xev(); - -export default function() { - const log = []; - - const p = childProcess.fork(__dirname + '/hashtags-stats-child.js'); - - p.on('message', stats => { - ev.emit('hashtagsStats', stats); - log.push(stats); - if (log.length > 30) log.shift(); - }); - - ev.on('requestHashTagsStatsLog', id => { - ev.emit('hashtagsStatsLog:' + id, log); - }); -} diff --git a/src/daemons/notes-stats.ts b/src/daemons/notes-stats.ts index 3094c34af0..021e6d64a7 100644 --- a/src/daemons/notes-stats.ts +++ b/src/daemons/notes-stats.ts @@ -4,7 +4,7 @@ import Xev from 'xev'; const ev = new Xev(); export default function() { - const log = []; + const log: any[] = []; const p = childProcess.fork(__dirname + '/notes-stats-child.js'); diff --git a/src/daemons/server-stats.ts b/src/daemons/server-stats.ts index 1403402508..5c793c6624 100644 --- a/src/daemons/server-stats.ts +++ b/src/daemons/server-stats.ts @@ -11,14 +11,14 @@ const interval = 1000; * Report server stats regularly */ export default function() { - const log = []; + const log: any[] = []; ev.on('requestServerStatsLog', id => { ev.emit('serverStatsLog:' + id, log); }); async function tick() { - osUtils.cpuUsage(cpuUsage => { + osUtils.cpuUsage((cpuUsage: number) => { const disk = diskusage.checkSync(os.platform() == 'win32' ? 'c:' : '/'); const stats = { cpu_usage: cpuUsage, |