From b6eb64a5a01d6685bcb50a9b423330d0b2f3e22f Mon Sep 17 00:00:00 2001 From: mrq Date: Fri, 21 Aug 2026 20:20:24 +0200 Subject: [PATCH 1/2] report disk usage where the data actually lives --- README.md | 1 + setup/args.go | 2 ++ swarmpit/task/stats.go | 13 ++++++++++- swarmpit/task/stats_test.go | 46 +++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e0623a..e0002be 100755 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ docker run -d \ - STATS_FREQUENCY - default to **30** - EVENT_ENDPOINT - default to **http://app:8080/events** - HEALTH_CHECK_ENDPOINT - default to **http://app:8080/version** +- DISK_PATH - mountpoint reported as node disk usage, default to **/** (**\\** on windows) - DEBUG_EVENT - default to **false** - DEBUG_STATS - default to **false** diff --git a/setup/args.go b/setup/args.go index 5bc9b21..52d88a0 100644 --- a/setup/args.go +++ b/setup/args.go @@ -14,6 +14,7 @@ type args struct { StatsFrequency int `json:"stats_frequency"` EventEndpoint string `json:"event_endpoint"` HealthCheckEndpoint string `json:"healthcheck_endpoint"` + DiskPath string `json:"disk_path"` Debug debug `json:"debug"` } @@ -22,6 +23,7 @@ func GetArgs() *args { StatsFrequency: getIntValue(30, "STATS_FREQUENCY"), EventEndpoint: getStringValue("http://app:8080/events", "EVENT_ENDPOINT"), HealthCheckEndpoint: getStringValue("http://app:8080/version", "HEALTH_CHECK_ENDPOINT"), + DiskPath: getStringValue("", "DISK_PATH"), Debug: debug{ Event: getBooleanValue(false, "DEBUG_EVENT"), Stats: getBooleanValue(false, "DEBUG_STATS")}, diff --git a/swarmpit/task/stats.go b/swarmpit/task/stats.go index b319607..dc17974 100644 --- a/swarmpit/task/stats.go +++ b/swarmpit/task/stats.go @@ -63,9 +63,20 @@ func getPath() string { return "/" } +// diskPath is the mountpoint reported as the node's disk usage. defaults to the +// platform root, override with DISK_PATH when data lives on another partition. +func diskPath() string { + if arg.DiskPath != "" { + return arg.DiskPath + } + return getPath() +} + func DiskUsage() (ds DiskStatus) { - diskStat, err := disk.Usage(getPath()) + path := diskPath() + diskStat, err := disk.Usage(path) if err != nil { + log.Printf("ERROR: Disk usage fetching failed for %s: %s\n", path, err) return } diff --git a/swarmpit/task/stats_test.go b/swarmpit/task/stats_test.go index 954c81a..cd75606 100644 --- a/swarmpit/task/stats_test.go +++ b/swarmpit/task/stats_test.go @@ -120,3 +120,49 @@ func TestContainersUsageSurvivesABadContainer(t *testing.T) { t.Fatalf("expected container aaa, got %+v", got[0]) } } + +// DISK_PATH lets a node report the partition its data actually lives on +// instead of always reporting root. See swarmpit/agent#5. +func TestDiskPathDefaultsToPlatformRoot(t *testing.T) { + original := arg.DiskPath + defer func() { arg.DiskPath = original }() + + arg.DiskPath = "" + if got := diskPath(); got != getPath() { + t.Fatalf("expected the platform root %q, got %q", getPath(), got) + } +} + +func TestDiskPathHonoursOverride(t *testing.T) { + original := arg.DiskPath + defer func() { arg.DiskPath = original }() + + arg.DiskPath = "/mnt/data" + if got := diskPath(); got != "/mnt/data" { + t.Fatalf("expected /mnt/data, got %q", got) + } +} + +func TestDiskUsageReportsTheConfiguredPath(t *testing.T) { + original := arg.DiskPath + defer func() { arg.DiskPath = original }() + + arg.DiskPath = "/" + root := DiskUsage() + if root.Total == 0 { + t.Fatal("expected a non-zero total for /") + } + if root.Used+root.Free > root.Total*2 { + t.Fatalf("implausible usage figures: %+v", root) + } +} + +func TestDiskUsageOnMissingPathIsZeroNotPanic(t *testing.T) { + original := arg.DiskPath + defer func() { arg.DiskPath = original }() + + arg.DiskPath = "/definitely/not/a/mountpoint" + if got := DiskUsage(); got != (DiskStatus{}) { + t.Fatalf("expected a zero status for a bad path, got %+v", got) + } +} From 19f104d93053db623a1621ccd06aeb699fccd1e7 Mon Sep 17 00:00:00 2001 From: mrq Date: Fri, 21 Aug 2026 20:35:41 +0200 Subject: [PATCH 2/2] document the docker env vars people keep rediscovering --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index e0002be..c8a41e3 100755 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ docker run -d \ - DEBUG_EVENT - default to **false** - DEBUG_STATS - default to **false** +The docker client is configured from the standard docker environment variables: + +- DOCKER_HOST - docker endpoint, default to the mounted **/var/run/docker.sock**. Set to e.g. **tcp://proxy:2375** to go through a socket proxy instead of mounting the socket +- DOCKER_API_VERSION - docker api version used by the client. Must be supported by your engine, docker 29 dropped everything below **1.44** +- DOCKER_CERT_PATH, DOCKER_TLS_VERIFY - tls settings for a remote endpoint + ## Important! In case you are deploying agent inside Swarmpit [stack](https://github.com/swarmpit/swarmpit/blob/master/docker-compose.yml)