Fix: sum throughput data for docker stats (#2334)

This commit is contained in:
shamoon
2023-11-16 23:55:04 -08:00
committed by GitHub
parent c9991bc2a2
commit 7f50f6cfaa
2 changed files with 20 additions and 5 deletions

View File

@@ -16,3 +16,18 @@ export function calculateUsedMemory(stats) {
stats.memory_stats.usage - (stats.memory_stats.total_inactive_file ?? stats.memory_stats.stats?.inactive_file ?? 0)
);
}
export function calculateThroughput(stats) {
let rx_bytes = 0;
let tx_bytes = 0;
if (stats.networks?.network) {
rx_bytes = stats.networks?.network.rx_bytes;
tx_bytes = stats.networks?.network.tx_bytes;
} else if (stats.networks && Array.isArray(Object.values(stats.networks))) {
Object.values(stats.networks).forEach((containerInterface) => {
rx_bytes += containerInterface.rx_bytes;
tx_bytes += containerInterface.tx_bytes;
});
}
return { rx_bytes, tx_bytes };
}