From c6fe79809286ca4a886a2a8e01efb4201bb5a2c1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 3 Jan 2021 22:38:32 +0900 Subject: サーバー情報ウィジェット MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/daemons/server-stats.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/daemons') diff --git a/src/daemons/server-stats.ts b/src/daemons/server-stats.ts index 88df421ba0..57691fbc00 100644 --- a/src/daemons/server-stats.ts +++ b/src/daemons/server-stats.ts @@ -6,6 +6,9 @@ const ev = new Xev(); const interval = 2000; +const roundCpu = (num: number) => Math.round(num * 1000) / 1000; +const round = (num: number) => Math.round(num * 10) / 10; + /** * Report server stats regularly */ @@ -23,18 +26,18 @@ export default function() { const fsStats = await fs(); const stats = { - cpu: cpu, + cpu: roundCpu(cpu), mem: { - used: memStats.used, - active: memStats.active, + used: round(memStats.used), + active: round(memStats.active), }, net: { - rx: Math.max(0, netStats.rx_sec), - tx: Math.max(0, netStats.tx_sec), + rx: round(Math.max(0, netStats.rx_sec)), + tx: round(Math.max(0, netStats.tx_sec)), }, fs: { - r: Math.max(0, fsStats.rIO_sec), - w: Math.max(0, fsStats.wIO_sec), + r: round(Math.max(0, fsStats.rIO_sec)), + w: round(Math.max(0, fsStats.wIO_sec)), } }; ev.emit('serverStats', stats); -- cgit v1.2.3-freya