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

@@ -80,14 +80,14 @@ async function getDockerStats() {
const now = Date.now();
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;
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
const memoryUsage = stats.memory_stats.usage / 1024 / 1024; // MB
// Memory usage in GB
const memoryUsage = (stats.memory_stats.usage / (1024 * 1024 * 1024)).toFixed(2);
// Network stats
const networkStats = stats.networks?.eth0 || { rx_bytes: 0, tx_bytes: 0 };
@@ -113,7 +113,7 @@ async function getDockerStats() {
id: containerId.substring(0, 12),
name: container.Names[0].replace(/^\//, ''),
cpu: cpuUsage.toFixed(2),
memory: memoryUsage.toFixed(2),
memory: memoryUsage,
network: {
received: formatBytes(receivedRate),
sent: formatBytes(sentRate)
@@ -129,7 +129,7 @@ async function getDockerStats() {
// Aggregate totals
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) => ({
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)