From af8707644f779931e97c9c77d95bab5077ae5e99 Mon Sep 17 00:00:00 2001 From: posimai Date: Tue, 31 Mar 2026 10:02:55 +0900 Subject: [PATCH] feat(station): add disk, load average, alert banner to system monitor server.js: /api/health now includes disk usage (df -B1 /) and load_avg (os.loadavg) + cpu_count. station.html: disk bar, load average chips with warn/crit coloring vs cpu count, alert banner highlights issues. Co-Authored-By: Claude Sonnet 4.6 --- posimai-dev/server.js | 22 ++ posimai-dev/station.html | 422 ++++++++++++++++++++++----------------- 2 files changed, 260 insertions(+), 184 deletions(-) diff --git a/posimai-dev/server.js b/posimai-dev/server.js index 69579916..3fb3d427 100644 --- a/posimai-dev/server.js +++ b/posimai-dev/server.js @@ -7,6 +7,7 @@ const https = require('https'); const fs = require('fs'); const path = require('path'); const os = require('os'); +const { execSync } = require('child_process'); const app = express(); const PORT = process.env.PORT || 3333; @@ -63,13 +64,34 @@ app.get('/api/health', (req, res) => { return sum + (dTotal > 0 ? (1 - dIdle / dTotal) * 100 : 0); }, 0) / s1.length; + // Disk usage + let disk = null; + try { + const dfOut = execSync('df -B1 / 2>/dev/null', { timeout: 2000 }).toString(); + const parts = dfOut.trim().split('\n')[1].split(/\s+/); + const totalB = parseInt(parts[1]); + const usedB = parseInt(parts[2]); + disk = { + total_gb: Math.round(totalB / 1e9 * 10) / 10, + used_gb: Math.round(usedB / 1e9 * 10) / 10, + use_pct: Math.round(usedB / totalB * 100), + }; + } catch (_) {} + + // Load average (1 / 5 / 15 min) and CPU count + const loadAvg = os.loadavg(); + const cpuCount = os.cpus().length; + res.json({ ok: true, hostname: os.hostname(), uptime_s: Math.floor(os.uptime()), cpu_pct: Math.round(cpuPct), + cpu_count: cpuCount, + load_avg: loadAvg.map(l => Math.round(l * 100) / 100), mem_used_mb: Math.round((total - mem) / 1024 / 1024), mem_total_mb: Math.round(total / 1024 / 1024), + disk, active_sessions: wss.clients ? wss.clients.size : 0, node_version: process.version, platform: os.platform(), diff --git a/posimai-dev/station.html b/posimai-dev/station.html index 5e68fd57..925f51fe 100644 --- a/posimai-dev/station.html +++ b/posimai-dev/station.html @@ -9,7 +9,7 @@ - + @@ -371,35 +395,37 @@
- + +
-
00:00:00
-
+ +
+ + +
+
-
-
- - Ubuntu PC -
+
+
Ubuntu PC
CPU - — % +
@@ -407,11 +433,37 @@
Memory - — MB +
+
+
+ Disk (/) + +
+
+
+ +
+
Load Average
+
+
+
1 min
+
+
+
+
5 min
+
+
+
+
15 min
+
+
+
+
+
Uptime
@@ -438,19 +490,16 @@
-
-
- - Services -
+
+
Services
+
- +
posimai-station
- -
次の更新まで 30s
+