mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-25 17:35:12 +00:00
サーバーの統計情報をメモリに記憶するようにするなど
This commit is contained in:
parent
726d5a177e
commit
6eff8fde74
5 changed files with 41 additions and 7 deletions
|
@ -218,6 +218,6 @@
|
|||
"webpack-cli": "2.1.4",
|
||||
"websocket": "1.0.26",
|
||||
"ws": "5.2.0",
|
||||
"xev": "2.0.0"
|
||||
"xev": "2.0.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,9 +76,15 @@ export default Vue.extend({
|
|||
},
|
||||
mounted() {
|
||||
this.connection.on('stats', this.onStats);
|
||||
this.connection.on('statsLog', this.onStatsLog);
|
||||
this.connection.send({
|
||||
type: 'requestLog',
|
||||
id: Math.random().toString()
|
||||
});
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.connection.off('stats', this.onStats);
|
||||
this.connection.off('statsLog', this.onStatsLog);
|
||||
},
|
||||
methods: {
|
||||
onStats(stats) {
|
||||
|
@ -94,6 +100,9 @@ export default Vue.extend({
|
|||
|
||||
this.cpuP = (stats.cpu_usage * 100).toFixed(0);
|
||||
this.memP = (stats.mem.used / stats.mem.total * 100).toFixed(0);
|
||||
},
|
||||
onStatsLog(statsLog) {
|
||||
statsLog.forEach(stats => this.onStats(stats));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@ import ProgressBar from './utils/cli/progressbar';
|
|||
import EnvironmentInfo from './utils/environmentInfo';
|
||||
import MachineInfo from './utils/machineInfo';
|
||||
import DependencyInfo from './utils/dependencyInfo';
|
||||
import stats from './utils/stats';
|
||||
import serverStats from './server-stats';
|
||||
|
||||
import loadConfig from './config/load';
|
||||
import { Config } from './config/types';
|
||||
|
@ -49,7 +49,7 @@ function main() {
|
|||
masterMain(opt);
|
||||
|
||||
ev.mount();
|
||||
stats();
|
||||
serverStats();
|
||||
} else {
|
||||
workerMain(opt);
|
||||
}
|
||||
|
|
|
@ -9,10 +9,16 @@ const ev = new Xev();
|
|||
* Report stats regularly
|
||||
*/
|
||||
export default function() {
|
||||
const log = [];
|
||||
|
||||
ev.on('requestServerStatsLog', id => {
|
||||
ev.emit('serverStatsLog:' + id, log);
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
osUtils.cpuUsage(cpuUsage => {
|
||||
const disk = diskusage.checkSync(os.platform() == 'win32' ? 'c:' : '/');
|
||||
ev.emit('stats', {
|
||||
const stats = {
|
||||
cpu_usage: cpuUsage,
|
||||
mem: {
|
||||
total: os.totalmem(),
|
||||
|
@ -21,7 +27,10 @@ export default function() {
|
|||
disk,
|
||||
os_uptime: os.uptime(),
|
||||
process_uptime: process.uptime()
|
||||
});
|
||||
};
|
||||
ev.emit('serverStats', stats);
|
||||
log.push(stats);
|
||||
if (log.length > 50) log.shift();
|
||||
});
|
||||
}, 1000);
|
||||
}
|
|
@ -11,9 +11,25 @@ export default function(request: websocket.request, connection: websocket.connec
|
|||
}));
|
||||
};
|
||||
|
||||
ev.addListener('stats', onStats);
|
||||
connection.on('message', async data => {
|
||||
const msg = JSON.parse(data.utf8Data);
|
||||
|
||||
switch (msg.type) {
|
||||
case 'requestLog':
|
||||
ev.once('serverStatsLog:' + msg.id, statsLog => {
|
||||
connection.send(JSON.stringify({
|
||||
type: 'statsLog',
|
||||
body: statsLog
|
||||
}));
|
||||
});
|
||||
ev.emit('requestServerStatsLog', msg.id);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
ev.addListener('serverStats', onStats);
|
||||
|
||||
connection.on('close', () => {
|
||||
ev.removeListener('stats', onStats);
|
||||
ev.removeListener('serverStats', onStats);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue