From 268e364bd4814d1fe0bcd344f32c87a5eb73b3e6 Mon Sep 17 00:00:00 2001 From: Henry Dollman Date: Sun, 29 Sep 2024 12:36:19 -0400 Subject: [PATCH] update MemoryStats type --- beszel/internal/agent/docker.go | 4 ++-- beszel/internal/entities/container/container.go | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/beszel/internal/agent/docker.go b/beszel/internal/agent/docker.go index d89bdce..bc08269 100644 --- a/beszel/internal/agent/docker.go +++ b/beszel/internal/agent/docker.go @@ -117,9 +117,9 @@ func (a *Agent) getContainerStats(ctr container.ApiInfo) (*container.Stats, erro } // memory (https://docs.docker.com/reference/cli/docker/container/stats/) - memCache := res.MemoryStats.Stats["inactive_file"] + memCache := res.MemoryStats.Stats.InactiveFile if memCache == 0 { - memCache = res.MemoryStats.Stats["cache"] + memCache = res.MemoryStats.Stats.Cache } usedMemory := res.MemoryStats.Usage - memCache diff --git a/beszel/internal/entities/container/container.go b/beszel/internal/entities/container/container.go index a4f3309..294f2bb 100644 --- a/beszel/internal/entities/container/container.go +++ b/beszel/internal/entities/container/container.go @@ -85,15 +85,13 @@ type CPUUsage struct { } type MemoryStats struct { - // current res_counter usage for memory Usage uint64 `json:"usage,omitempty"` - Cache uint64 `json:"cache,omitempty"` + // all the stats exported via memory.stat. + Stats MemoryStatsStats `json:"stats,omitempty"` // maximum usage ever recorded. // MaxUsage uint64 `json:"max_usage,omitempty"` // TODO(vishh): Export these as stronger types. - // all the stats exported via memory.stat. - Stats map[string]uint64 `json:"stats,omitempty"` // number of times memory usage hits limits. // Failcnt uint64 `json:"failcnt,omitempty"` // Limit uint64 `json:"limit,omitempty"` @@ -106,6 +104,11 @@ type MemoryStats struct { // PrivateWorkingSet uint64 `json:"privateworkingset,omitempty"` } +type MemoryStatsStats struct { + Cache uint64 `json:"cache,omitempty"` + InactiveFile uint64 `json:"inactive_file,omitempty"` +} + type NetworkStats struct { // Bytes received. Windows and Linux. RxBytes uint64 `json:"rx_bytes"`