mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-14 05:57:32 -07:00
サーバーの統計情報をメモリに記憶するようにするなど
This commit is contained in:
parent
56165e9bb6
commit
38c57030f8
5 changed files with 41 additions and 7 deletions
|
@ -218,6 +218,6 @@
|
||||||
"webpack-cli": "2.1.4",
|
"webpack-cli": "2.1.4",
|
||||||
"websocket": "1.0.26",
|
"websocket": "1.0.26",
|
||||||
"ws": "5.2.0",
|
"ws": "5.2.0",
|
||||||
"xev": "2.0.0"
|
"xev": "2.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,9 +76,15 @@ export default Vue.extend({
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.connection.on('stats', this.onStats);
|
this.connection.on('stats', this.onStats);
|
||||||
|
this.connection.on('statsLog', this.onStatsLog);
|
||||||
|
this.connection.send({
|
||||||
|
type: 'requestLog',
|
||||||
|
id: Math.random().toString()
|
||||||
|
});
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.connection.off('stats', this.onStats);
|
this.connection.off('stats', this.onStats);
|
||||||
|
this.connection.off('statsLog', this.onStatsLog);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onStats(stats) {
|
onStats(stats) {
|
||||||
|
@ -94,6 +100,9 @@ export default Vue.extend({
|
||||||
|
|
||||||
this.cpuP = (stats.cpu_usage * 100).toFixed(0);
|
this.cpuP = (stats.cpu_usage * 100).toFixed(0);
|
||||||
this.memP = (stats.mem.used / stats.mem.total * 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 EnvironmentInfo from './utils/environmentInfo';
|
||||||
import MachineInfo from './utils/machineInfo';
|
import MachineInfo from './utils/machineInfo';
|
||||||
import DependencyInfo from './utils/dependencyInfo';
|
import DependencyInfo from './utils/dependencyInfo';
|
||||||
import stats from './utils/stats';
|
import serverStats from './server-stats';
|
||||||
|
|
||||||
import loadConfig from './config/load';
|
import loadConfig from './config/load';
|
||||||
import { Config } from './config/types';
|
import { Config } from './config/types';
|
||||||
|
@ -49,7 +49,7 @@ function main() {
|
||||||
masterMain(opt);
|
masterMain(opt);
|
||||||
|
|
||||||
ev.mount();
|
ev.mount();
|
||||||
stats();
|
serverStats();
|
||||||
} else {
|
} else {
|
||||||
workerMain(opt);
|
workerMain(opt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,16 @@ const ev = new Xev();
|
||||||
* Report stats regularly
|
* Report stats regularly
|
||||||
*/
|
*/
|
||||||
export default function() {
|
export default function() {
|
||||||
|
const log = [];
|
||||||
|
|
||||||
|
ev.on('requestServerStatsLog', id => {
|
||||||
|
ev.emit('serverStatsLog:' + id, log);
|
||||||
|
});
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
osUtils.cpuUsage(cpuUsage => {
|
osUtils.cpuUsage(cpuUsage => {
|
||||||
const disk = diskusage.checkSync(os.platform() == 'win32' ? 'c:' : '/');
|
const disk = diskusage.checkSync(os.platform() == 'win32' ? 'c:' : '/');
|
||||||
ev.emit('stats', {
|
const stats = {
|
||||||
cpu_usage: cpuUsage,
|
cpu_usage: cpuUsage,
|
||||||
mem: {
|
mem: {
|
||||||
total: os.totalmem(),
|
total: os.totalmem(),
|
||||||
|
@ -21,7 +27,10 @@ export default function() {
|
||||||
disk,
|
disk,
|
||||||
os_uptime: os.uptime(),
|
os_uptime: os.uptime(),
|
||||||
process_uptime: process.uptime()
|
process_uptime: process.uptime()
|
||||||
});
|
};
|
||||||
|
ev.emit('serverStats', stats);
|
||||||
|
log.push(stats);
|
||||||
|
if (log.length > 50) log.shift();
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 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', () => {
|
connection.on('close', () => {
|
||||||
ev.removeListener('stats', onStats);
|
ev.removeListener('serverStats', onStats);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue