Container table CPU = 6 Cores RAM = GB

This commit is contained in:
MCHost
2025-07-14 19:35:35 -04:00
parent 4941125315
commit 2ed0f3a259
2 changed files with 10 additions and 10 deletions

View File

@@ -148,7 +148,7 @@
<tr> <tr>
<th class="px-6 py-3">Name</th> <th class="px-6 py-3">Name</th>
<th class="px-6 py-3">CPU Usage (%)</th> <th class="px-6 py-3">CPU Usage (%)</th>
<th class="px-6 py-3">Memory Usage (MB)</th> <th class="px-6 py-3">Memory Usage (GB)</th>
<th class="px-6 py-3">State</th> <th class="px-6 py-3">State</th>
</tr> </tr>
</thead> </thead>
@@ -163,7 +163,7 @@
<tr> <tr>
<th class="px-6 py-3">Name</th> <th class="px-6 py-3">Name</th>
<th class="px-6 py-3">CPU Usage (%)</th> <th class="px-6 py-3">CPU Usage (%)</th>
<th class="px-6 py-3">Memory Usage (MB)</th> <th class="px-6 py-3">Memory Usage (GB)</th>
<th class="px-6 py-3">State</th> <th class="px-6 py-3">State</th>
</tr> </tr>
</thead> </thead>
@@ -577,7 +577,7 @@
<tr> <tr>
<td class="px-6 py-4">${c.name}</td> <td class="px-6 py-4">${c.name}</td>
<td class="px-6 py-4">${c.cpu}%</td> <td class="px-6 py-4">${c.cpu}%</td>
<td class="px-6 py-4">${c.memory} MB</td> <td class="px-6 py-4">${c.memory} GB</td>
<td class="px-6 py-4">${c.state}</td> <td class="px-6 py-4">${c.state}</td>
</tr> </tr>
`).join('') || ''; `).join('') || '';
@@ -585,7 +585,7 @@
<tr> <tr>
<td class="px-6 py-4">${c.name}</td> <td class="px-6 py-4">${c.name}</td>
<td class="px-6 py-4">${c.cpu}%</td> <td class="px-6 py-4">${c.cpu}%</td>
<td class="px-6 py-4">${c.memory} MB</td> <td class="px-6 py-4">${c.memory} GB</td>
<td class="px-6 py-4">${c.state}</td> <td class="px-6 py-4">${c.state}</td>
</tr> </tr>
`).join('') || ''; `).join('') || '';

View File

@@ -80,14 +80,14 @@ async function getDockerStats() {
const now = Date.now(); const now = Date.now();
const timeDiffMs = now - prev.time; const timeDiffMs = now - prev.time;
// Calculate CPU usage as percentage of total CPU capacity // Calculate CPU usage as percentage relative to the 6 cores limit
let cpuUsage = 0; let cpuUsage = 0;
if (systemDelta > 0 && timeDiffMs > 0) { if (systemDelta > 0 && timeDiffMs > 0) {
cpuUsage = (cpuDelta / systemDelta) * stats.cpu_stats.online_cpus / TOTAL_CORES * 100; cpuUsage = (cpuDelta / systemDelta) * (TOTAL_CORES / 6) * 100;
} }
// Memory usage // Memory usage in GB
const memoryUsage = stats.memory_stats.usage / 1024 / 1024; // MB const memoryUsage = (stats.memory_stats.usage / (1024 * 1024 * 1024)).toFixed(2);
// Network stats // Network stats
const networkStats = stats.networks?.eth0 || { rx_bytes: 0, tx_bytes: 0 }; const networkStats = stats.networks?.eth0 || { rx_bytes: 0, tx_bytes: 0 };
@@ -113,7 +113,7 @@ async function getDockerStats() {
id: containerId.substring(0, 12), id: containerId.substring(0, 12),
name: container.Names[0].replace(/^\//, ''), name: container.Names[0].replace(/^\//, ''),
cpu: cpuUsage.toFixed(2), cpu: cpuUsage.toFixed(2),
memory: memoryUsage.toFixed(2), memory: memoryUsage,
network: { network: {
received: formatBytes(receivedRate), received: formatBytes(receivedRate),
sent: formatBytes(sentRate) sent: formatBytes(sentRate)
@@ -129,7 +129,7 @@ async function getDockerStats() {
// Aggregate totals // Aggregate totals
const totalCpu = containerStats.reduce((sum, c) => sum + parseFloat(c.cpu), 0).toFixed(2); const totalCpu = containerStats.reduce((sum, c) => sum + parseFloat(c.cpu), 0).toFixed(2);
const totalMemory = (containerStats.reduce((sum, c) => sum + parseFloat(c.memory), 0) / 1024).toFixed(2); // Convert MB to GB const totalMemory = containerStats.reduce((sum, c) => sum + parseFloat(c.memory), 0).toFixed(2); // Already in GB
const totalNetwork = containerStats.reduce((sum, c) => ({ const totalNetwork = containerStats.reduce((sum, c) => ({
received: sum.received + parseFloat(c.network.received.value) * (c.network.received.unit === 'GB/s' ? 1e9 : c.network.received.unit === 'MB/s' ? 1e6 : c.network.received.unit === 'KB/s' ? 1e3 : 1), received: sum.received + parseFloat(c.network.received.value) * (c.network.received.unit === 'GB/s' ? 1e9 : c.network.received.unit === 'MB/s' ? 1e6 : c.network.received.unit === 'KB/s' ? 1e3 : 1),
sent: sum.sent + parseFloat(c.network.sent.value) * (c.network.sent.unit === 'GB/s' ? 1e9 : c.network.sent.unit === 'MB/s' ? 1e6 : c.network.sent.unit === 'KB/s' ? 1e3 : 1) sent: sum.sent + parseFloat(c.network.sent.value) * (c.network.sent.unit === 'GB/s' ? 1e9 : c.network.sent.unit === 'MB/s' ? 1e6 : c.network.sent.unit === 'KB/s' ? 1e3 : 1)