Ditzzy AF
commited on
Commit
·
f937534
1
Parent(s):
ec5ee9a
fix: Improve Windows network stats accuracy and terminal height
Browse files- Enhanced Windows network stats retrieval to accurately calculate RX and TX speeds.
- Adjusted terminal height in the UI for better responsiveness and usability.
- app.js +26 -6
- views/terminal.ejs +7 -2
app.js
CHANGED
|
@@ -173,10 +173,32 @@ class SystemMonitor {
|
|
| 173 |
async getNetworkStats() {
|
| 174 |
try {
|
| 175 |
if (isWindows) {
|
| 176 |
-
//
|
| 177 |
-
const { stdout } = await execAsync(
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
} else {
|
| 181 |
// Linux - read from /proc/net/dev
|
| 182 |
const data = await fs.readFile('/proc/net/dev', 'utf8');
|
|
@@ -190,8 +212,6 @@ class SystemMonitor {
|
|
| 190 |
totalTx += parseInt(parts[8]) || 0;
|
| 191 |
}
|
| 192 |
}
|
| 193 |
-
|
| 194 |
-
// Calculate speed if we have previous data
|
| 195 |
if (this.previousNetworkStats) {
|
| 196 |
const rxSpeed = Math.max(0, totalRx - this.previousNetworkStats.rx);
|
| 197 |
const txSpeed = Math.max(0, totalTx - this.previousNetworkStats.tx);
|
|
|
|
| 173 |
async getNetworkStats() {
|
| 174 |
try {
|
| 175 |
if (isWindows) {
|
| 176 |
+
// Jalankan PowerShell dengan benar
|
| 177 |
+
const { stdout } = await execAsync(
|
| 178 |
+
'powershell -Command "Get-NetAdapterStatistics | Select-Object -Property ReceivedBytes, SentBytes | ConvertTo-Json"'
|
| 179 |
+
);
|
| 180 |
+
// Ambil total RX dan TX dari semua adapter
|
| 181 |
+
const stats = JSON.parse(stdout);
|
| 182 |
+
let totalRx = 0, totalTx = 0;
|
| 183 |
+
if (Array.isArray(stats)) {
|
| 184 |
+
stats.forEach(s => {
|
| 185 |
+
totalRx += parseInt(s.ReceivedBytes) || 0;
|
| 186 |
+
totalTx += parseInt(s.SentBytes) || 0;
|
| 187 |
+
});
|
| 188 |
+
} else if (stats) {
|
| 189 |
+
totalRx = parseInt(stats.ReceivedBytes) || 0;
|
| 190 |
+
totalTx = parseInt(stats.SentBytes) || 0;
|
| 191 |
+
}
|
| 192 |
+
// Hitung delta per detik (seperti di Linux)
|
| 193 |
+
if (this.previousNetworkStats) {
|
| 194 |
+
const rxSpeed = Math.max(0, totalRx - this.previousNetworkStats.rx);
|
| 195 |
+
const txSpeed = Math.max(0, totalTx - this.previousNetworkStats.tx);
|
| 196 |
+
this.previousNetworkStats = { rx: totalRx, tx: totalTx };
|
| 197 |
+
return { rx: rxSpeed, tx: txSpeed };
|
| 198 |
+
} else {
|
| 199 |
+
this.previousNetworkStats = { rx: totalRx, tx: totalTx };
|
| 200 |
+
return { rx: 0, tx: 0 };
|
| 201 |
+
}
|
| 202 |
} else {
|
| 203 |
// Linux - read from /proc/net/dev
|
| 204 |
const data = await fs.readFile('/proc/net/dev', 'utf8');
|
|
|
|
| 212 |
totalTx += parseInt(parts[8]) || 0;
|
| 213 |
}
|
| 214 |
}
|
|
|
|
|
|
|
| 215 |
if (this.previousNetworkStats) {
|
| 216 |
const rxSpeed = Math.max(0, totalRx - this.previousNetworkStats.rx);
|
| 217 |
const txSpeed = Math.max(0, totalTx - this.previousNetworkStats.tx);
|
views/terminal.ejs
CHANGED
|
@@ -126,8 +126,13 @@
|
|
| 126 |
padding: 16px;
|
| 127 |
background: var(--bg);
|
| 128 |
border-radius: 0 0 18px 18px;
|
| 129 |
-
min-height: 180px;
|
| 130 |
min-width: 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
}
|
| 132 |
.connection-status {
|
| 133 |
position: absolute;
|
|
@@ -269,7 +274,7 @@
|
|
| 269 |
.logo { font-size: 14px; }
|
| 270 |
.terminal-card { margin: 8px 2px 0 2px; border-radius: 10px; }
|
| 271 |
.terminal-header { border-radius: 10px 10px 0 0; padding: 8px 8px; }
|
| 272 |
-
#terminal { border-radius: 0 0 10px 10px; padding: 6px; min-height:
|
| 273 |
.sidebar { border-radius: 10px 10px 0 0; }
|
| 274 |
.sidebar-inner { padding: 8px 2px 2px 2px; }
|
| 275 |
}
|
|
|
|
| 126 |
padding: 16px;
|
| 127 |
background: var(--bg);
|
| 128 |
border-radius: 0 0 18px 18px;
|
|
|
|
| 129 |
min-width: 0;
|
| 130 |
+
min-height: 180px;
|
| 131 |
+
max-height: 60vh;
|
| 132 |
+
height: 40vh;
|
| 133 |
+
transition: height 0.2s;
|
| 134 |
+
box-sizing: border-box;
|
| 135 |
+
overflow: auto;
|
| 136 |
}
|
| 137 |
.connection-status {
|
| 138 |
position: absolute;
|
|
|
|
| 274 |
.logo { font-size: 14px; }
|
| 275 |
.terminal-card { margin: 8px 2px 0 2px; border-radius: 10px; }
|
| 276 |
.terminal-header { border-radius: 10px 10px 0 0; padding: 8px 8px; }
|
| 277 |
+
#terminal { border-radius: 0 0 10px 10px; padding: 6px; min-height: 90px; height: 28vh; max-height: 35vh; }
|
| 278 |
.sidebar { border-radius: 10px 10px 0 0; }
|
| 279 |
.sidebar-inner { padding: 8px 2px 2px 2px; }
|
| 280 |
}
|