mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-10-31 06:24:02 +00:00 
			
		
		
		
	Merge pull request #1156 from SebastianOsinski/improve_docker_memory_stats
Display Docker container's used memory instead of total memory
This commit is contained in:
		
						commit
						bffda3240a
					
				| @ -3,7 +3,7 @@ | ||||
| 	"build": { | ||||
| 		"dockerfile": "Dockerfile", | ||||
| 		"args": { | ||||
| 			"VARIANT": "18-buster" | ||||
| 			"VARIANT": "18-bullseye" | ||||
| 		} | ||||
| 	}, | ||||
| 	"customizations": { | ||||
|  | ||||
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -4,6 +4,7 @@ | ||||
| /node_modules | ||||
| /.pnp | ||||
| .pnp.js | ||||
| .pnpm-store | ||||
| 
 | ||||
| # testing | ||||
| /coverage | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| import useSWR from "swr"; | ||||
| import { useTranslation } from "next-i18next"; | ||||
| 
 | ||||
| import calculateCPUPercent from "./stats-helpers"; | ||||
| import { calculateCPUPercent, calculateUsedMemory } from "./stats-helpers"; | ||||
| 
 | ||||
| import Container from "components/services/widget/container"; | ||||
| import Block from "components/services/widget/block"; | ||||
| @ -47,7 +47,7 @@ export default function Component({ service }) { | ||||
|     <Container service={service}> | ||||
|       <Block label="docker.cpu" value={t("common.percent", { value: calculateCPUPercent(statsData.stats) })} /> | ||||
|       {statsData.stats.memory_stats.usage &&  | ||||
|         <Block label="docker.mem" value={t("common.bytes", { value: statsData.stats.memory_stats.usage })} /> | ||||
|         <Block label="docker.mem" value={t("common.bytes", { value: calculateUsedMemory(statsData.stats) })} /> | ||||
|       } | ||||
|       {network && ( | ||||
|         <> | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| export default function calculateCPUPercent(stats) { | ||||
| export function calculateCPUPercent(stats) { | ||||
|   let cpuPercent = 0.0; | ||||
|   const cpuDelta = stats.cpu_stats.cpu_usage.total_usage - stats.precpu_stats.cpu_usage.total_usage; | ||||
|   const systemDelta = stats.cpu_stats.system_cpu_usage - stats.precpu_stats.system_cpu_usage; | ||||
| @ -9,3 +9,7 @@ export default function calculateCPUPercent(stats) { | ||||
| 
 | ||||
|   return Math.round(cpuPercent * 10) / 10; | ||||
| } | ||||
| 
 | ||||
| export function calculateUsedMemory(stats) { | ||||
|   return stats.memory_stats.usage - (stats.memory_stats.stats.cache ?? 0) | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 shamoon
						shamoon