mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-04 08:20:58 +00:00 
			
		
		
		
	Fix: sum throughput data for docker stats (#2334)
This commit is contained in:
		
							parent
							
								
									c9991bc2a2
								
							
						
					
					
						commit
						7f50f6cfaa
					
				@ -1,7 +1,7 @@
 | 
			
		||||
import useSWR from "swr";
 | 
			
		||||
import { useTranslation } from "next-i18next";
 | 
			
		||||
 | 
			
		||||
import { calculateCPUPercent, calculateUsedMemory } from "./stats-helpers";
 | 
			
		||||
import { calculateCPUPercent, calculateUsedMemory, calculateThroughput } from "./stats-helpers";
 | 
			
		||||
 | 
			
		||||
import Container from "components/services/widget/container";
 | 
			
		||||
import Block from "components/services/widget/block";
 | 
			
		||||
@ -41,7 +41,7 @@ export default function Component({ service }) {
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const network = statsData.stats.networks?.eth0 || statsData.stats.networks?.network;
 | 
			
		||||
  const { rx_bytes, tx_bytes } = calculateThroughput(statsData.stats);
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <Container service={service}>
 | 
			
		||||
@ -49,10 +49,10 @@ export default function Component({ service }) {
 | 
			
		||||
      {statsData.stats.memory_stats.usage && (
 | 
			
		||||
        <Block label="docker.mem" value={t("common.bytes", { value: calculateUsedMemory(statsData.stats) })} />
 | 
			
		||||
      )}
 | 
			
		||||
      {network && (
 | 
			
		||||
      {statsData.stats.networks && (
 | 
			
		||||
        <>
 | 
			
		||||
          <Block label="docker.rx" value={t("common.bytes", { value: network.rx_bytes })} />
 | 
			
		||||
          <Block label="docker.tx" value={t("common.bytes", { value: network.tx_bytes })} />
 | 
			
		||||
          <Block label="docker.rx" value={t("common.bytes", { value: rx_bytes })} />
 | 
			
		||||
          <Block label="docker.tx" value={t("common.bytes", { value: tx_bytes })} />
 | 
			
		||||
        </>
 | 
			
		||||
      )}
 | 
			
		||||
    </Container>
 | 
			
		||||
 | 
			
		||||
@ -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 };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user