Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f8b87a4
show CPU and memory for containers on Windows Docker hosts
jotka Sep 19, 2026
8af79ff
add user-defined tags for containers and stacks with grid grouping
jotka Sep 19, 2026
ef9e405
add a toggle for the coloured group bands on the tag-grouped grids
jotka Sep 19, 2026
0ab846c
group the editor font and theme pickers above the preview
jotka Sep 19, 2026
aba356e
keep populated git stack env vars visible in the editor after saving
jotka Sep 19, 2026
c1084f7
don't send container died/killed notifications for a container being …
jotka Sep 19, 2026
0cc8c1a
skip hidden folders when scanning for stacks to adopt
jotka Sep 19, 2026
1f8c4a3
resolve secret-provider values for all stack lifecycle operations
jotka Sep 19, 2026
03b335d
update Podman Quadlet containers by handing the recreate to systemd
jotka Sep 19, 2026
aa242bc
search and filter containers by label
jotka Sep 19, 2026
b3e2b26
make the command palette fast and search stacks and containers
jotka Sep 19, 2026
246e637
correct the environment query param docs on container endpoints
jotka Sep 19, 2026
ac1aa1e
add an optional entrypoint field to the container create and edit modals
jotka Sep 19, 2026
1ecc38f
release housekeeping
jotka Sep 19, 2026
c6bbce8
derive the editor gutter background from the theme so it stands out o…
jotka Sep 19, 2026
4128efa
add selectable code editor color themes and fix gutter readability
jotka Sep 19, 2026
be98304
give the editor theme preview full width and honor the editor font
jotka Sep 19, 2026
eb9b5a7
show a shared container once per environment in the command palette
jotka Sep 19, 2026
6e89c6a
follow a cross-host jump to logs or a terminal already open on anothe…
jotka Sep 19, 2026
00781e8
put time and date format on one row and widen the theme picker
jotka Sep 19, 2026
8de1fda
add a clear (X) button to search fields
jotka Sep 19, 2026
3dba4b5
add an option to skip bind mounts when batch-scheduling environment b…
jotka Sep 19, 2026
37e43ed
control file ownership in the container file browser
jotka Sep 19, 2026
2235636
add a one-shot container exec API returning stdout, stderr and exit code
jotka Sep 19, 2026
a6111cb
honor a registry's configured http/https scheme when checking for ima…
jotka Sep 19, 2026
2a04098
scan from the registry when the daemon image export is incomplete
jotka Sep 19, 2026
76a407b
don't report a newer version tag that resolves to the image already r…
jotka Sep 19, 2026
525c921
match selfh.st icons whose reference differs from the image only by h…
jotka Sep 19, 2026
f1247f7
show memory limit and disk I/O for Windows containers
jotka Sep 19, 2026
99bf213
clarify the activity settings and fix the highlight toggle reverting …
jotka Sep 19, 2026
c4b1cec
send the user to the login page when their session expires
jotka Sep 19, 2026
9fb5fe0
point the Dockhand auto-update note at the built-in self-update
jotka Sep 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 71 additions & 22 deletions collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ type containerInfo struct {
}

type containerStats struct {
// Read/Preread timestamps and NumProcs are used for the Windows CPU formula,
// which has no system_cpu_usage to divide by (#1574).
Read string `json:"read"`
Preread string `json:"preread"`
NumProcs uint32 `json:"num_procs"`
CPUStats struct {
CPUUsage struct {
TotalUsage uint64 `json:"total_usage"`
Expand All @@ -97,13 +102,76 @@ type containerStats struct {
} `json:"precpu_stats"`
MemoryStats struct {
Usage uint64 `json:"usage"`
Stats struct {
// Windows reports memory as privateworkingset (already cache-free) instead
// of usage; a nil pointer means the payload is a Unix one (#1574).
PrivateWorkingSet *uint64 `json:"privateworkingset"`
Stats struct {
InactiveFile uint64 `json:"inactive_file"`
TotalInactiveFile uint64 `json:"total_inactive_file"`
} `json:"stats"`
} `json:"memory_stats"`
}

// calcCPUPercent mirrors src/lib/server/stats-calc-core.ts. Unix uses the
// cpu-vs-system delta ratio; Windows has no system_cpu_usage, so it uses the
// wall-clock formula (num_procs * elapsed) - detected by privateworkingset (#1574).
func calcCPUPercent(s *containerStats) float64 {
// Compare BEFORE subtracting: uint64 underflow (precpu > cpu on a first sample
// or a counter reset) would wrap to a huge positive and slip past a >0 guard,
// producing an absurd CPU%. A non-increasing counter means no usage -> 0.
cur := s.CPUStats.CPUUsage.TotalUsage
prev := s.PrecpuStats.CPUUsage.TotalUsage
if cur <= prev {
return 0
}
cpuDelta := float64(cur - prev)

if s.MemoryStats.PrivateWorkingSet != nil {
read, errR := time.Parse(time.RFC3339Nano, s.Read)
preread, errP := time.Parse(time.RFC3339Nano, s.Preread)
if errR != nil || errP != nil {
return 0
}
// possIntervals = num_procs * elapsed-MILLISECONDS; cpu% = cpuDelta / (possIntervals*100).
// Matches the Docker CLI / Portainer Windows formula and the TS core.
elapsedMs := float64(read.Sub(preread).Milliseconds())
possIntervals := float64(s.NumProcs) * elapsedMs
if possIntervals > 0 {
return cpuDelta / (possIntervals * 100)
}
return 0
}

curSys := s.CPUStats.SystemCPUUsage
prevSys := s.PrecpuStats.SystemCPUUsage
if curSys <= prevSys {
return 0
}
sysDelta := float64(curSys - prevSys)
cpuCount := s.CPUStats.OnlineCPUs
if cpuCount == 0 {
cpuCount = 1
}
return (cpuDelta / sysDelta) * float64(cpuCount) * 100
}

// calcMemUsage mirrors the TS core: Windows uses privateworkingset (cache-free),
// Unix subtracts inactive-file cache from usage.
func calcMemUsage(s *containerStats) uint64 {
if s.MemoryStats.PrivateWorkingSet != nil {
return *s.MemoryStats.PrivateWorkingSet
}
memUsage := s.MemoryStats.Usage
memCache := s.MemoryStats.Stats.InactiveFile
if memCache == 0 {
memCache = s.MemoryStats.Stats.TotalInactiveFile
}
if memCache > 0 && memCache < memUsage {
return memUsage - memCache
}
return memUsage
}

type dockerInfo struct {
MemTotal int64 `json:"MemTotal"`
NCPU int `json:"NCPU"`
Expand Down Expand Up @@ -496,27 +564,8 @@ func (m *manager) collectMetrics(env *environment) {
return
}

cpuDelta := float64(stats.CPUStats.CPUUsage.TotalUsage - stats.PrecpuStats.CPUUsage.TotalUsage)
sysDelta := float64(stats.CPUStats.SystemCPUUsage - stats.PrecpuStats.SystemCPUUsage)
cpuCount := stats.CPUStats.OnlineCPUs
if cpuCount == 0 {
cpuCount = 1
}

var cpuPct float64
if sysDelta > 0 && cpuDelta > 0 {
cpuPct = (cpuDelta / sysDelta) * float64(cpuCount) * 100
}

memUsage := stats.MemoryStats.Usage
memCache := stats.MemoryStats.Stats.InactiveFile
if memCache == 0 {
memCache = stats.MemoryStats.Stats.TotalInactiveFile
}
actualMem := memUsage
if memCache > 0 && memCache < memUsage {
actualMem = memUsage - memCache
}
cpuPct := calcCPUPercent(&stats)
actualMem := calcMemUsage(&stats)

results[idx] = statsResult{cpu: cpuPct, mem: actualMem}
}(i, c.ID)
Expand Down
109 changes: 109 additions & 0 deletions collector/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package main

import (
"encoding/json"
"math"
"testing"
)

// mustStats decodes a JSON stats payload into containerStats for the tests.
func mustStats(t *testing.T, jsonStr string) *containerStats {
t.Helper()
var s containerStats
if err := json.Unmarshal([]byte(jsonStr), &s); err != nil {
t.Fatalf("decode: %v", err)
}
return &s
}

const unixPayload = `{
"read": "2026-09-15T10:00:01Z",
"preread": "2026-09-15T10:00:00Z",
"cpu_stats": {"cpu_usage": {"total_usage": 2000000000}, "system_cpu_usage": 20000000000, "online_cpus": 4},
"precpu_stats": {"cpu_usage": {"total_usage": 1000000000}, "system_cpu_usage": 18000000000},
"memory_stats": {"usage": 209715200, "stats": {"inactive_file": 52428800}}
}`

// Windows: no system_cpu_usage, privateworkingset present, 1000ms elapsed, 2 procs.
const windowsPayload = `{
"read": "2026-09-15T10:00:01.0000000Z",
"preread": "2026-09-15T10:00:00.0000000Z",
"num_procs": 2,
"cpu_stats": {"cpu_usage": {"total_usage": 500000000}},
"precpu_stats": {"cpu_usage": {"total_usage": 400000000}},
"memory_stats": {"privateworkingset": 134217728}
}`

func closeTo(a, b float64) bool { return math.Abs(a-b) < 1e-6 }

func TestCalcCPUPercentUnix(t *testing.T) {
// cpuDelta=1e9, sysDelta=2e9, cpuCount=4 -> 0.5*4*100 = 200
got := calcCPUPercent(mustStats(t, unixPayload))
if !closeTo(got, 200) {
t.Fatalf("unix cpu: got %v want 200", got)
}
}

func TestCalcCPUPercentWindows(t *testing.T) {
// cpuDelta=1e8, elapsed=1000ms, num_procs=2 -> possIntervals=2000
// cpu = cpuDelta / (possIntervals*100) = 1e8/(2000*100) = 500. Matches the TS core.
got := calcCPUPercent(mustStats(t, windowsPayload))
want := 1e8 / (2 * 1000 * 100)
if !closeTo(got, want) {
t.Fatalf("windows cpu: got %v want %v", got, want)
}
if !closeTo(got, 500) {
t.Fatalf("windows cpu: got %v want 500", got)
}
if got <= 0 {
t.Fatalf("windows cpu must be > 0 (proves the Windows branch ran, not the Unix 0)")
}
}

func TestCalcCPUPercentWindowsZeroElapsed(t *testing.T) {
s := mustStats(t, windowsPayload)
s.Preread = s.Read // no elapsed time
if got := calcCPUPercent(s); got != 0 {
t.Fatalf("zero elapsed must be 0, got %v", got)
}
}

func TestCalcMemUsageUnix(t *testing.T) {
// 200MiB usage - 50MiB cache = 150MiB
got := calcMemUsage(mustStats(t, unixPayload))
if got != 150*1024*1024 {
t.Fatalf("unix mem: got %d want %d", got, 150*1024*1024)
}
}

func TestCalcMemUsageWindows(t *testing.T) {
// privateworkingset used directly, no cache subtraction
got := calcMemUsage(mustStats(t, windowsPayload))
if got != 128*1024*1024 {
t.Fatalf("windows mem: got %d want %d", got, 128*1024*1024)
}
if got == 0 {
t.Fatalf("windows mem must not be 0 (the #1574 symptom)")
}
}

func TestCalcCPUPercentCounterReset(t *testing.T) {
// precpu > cpu (counter reset / first sample). uint64 subtraction would wrap to a
// huge positive; the fix must return 0, not garbage. Both Unix and Windows branches.
unixReset := mustStats(t, `{"cpu_stats":{"cpu_usage":{"total_usage":1000},"system_cpu_usage":5000,"online_cpus":2},"precpu_stats":{"cpu_usage":{"total_usage":2000},"system_cpu_usage":4000},"memory_stats":{"usage":1000}}`)
if got := calcCPUPercent(unixReset); got != 0 {
t.Fatalf("unix counter reset must be 0 (no uint64 underflow garbage), got %v", got)
}
winReset := mustStats(t, `{"read":"2026-09-15T10:00:01Z","preread":"2026-09-15T10:00:00Z","num_procs":2,"cpu_stats":{"cpu_usage":{"total_usage":1000}},"precpu_stats":{"cpu_usage":{"total_usage":2000}},"memory_stats":{"privateworkingset":1000}}`)
if got := calcCPUPercent(winReset); got != 0 {
t.Fatalf("windows counter reset must be 0, got %v", got)
}
}

func TestCalcCPUPercentSystemCounterReset(t *testing.T) {
// cpu increases but SYSTEM counter went backwards -> sysDelta underflow guard.
s := mustStats(t, `{"cpu_stats":{"cpu_usage":{"total_usage":2000},"system_cpu_usage":4000,"online_cpus":2},"precpu_stats":{"cpu_usage":{"total_usage":1000},"system_cpu_usage":5000},"memory_stats":{"usage":1000}}`)
if got := calcCPUPercent(s); got != 0 {
t.Fatalf("system counter reset must be 0, got %v", got)
}
}
31 changes: 31 additions & 0 deletions drizzle-pg/0016_add_tags.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CREATE TABLE "container_tags" (
"id" serial PRIMARY KEY NOT NULL,
"container_name" text NOT NULL,
"environment_id" integer,
"tag_id" integer NOT NULL,
"created_at" timestamp DEFAULT now(),
CONSTRAINT "container_tags_container_name_environment_id_tag_id_unique" UNIQUE("container_name","environment_id","tag_id")
);
--> statement-breakpoint
CREATE TABLE "stack_tags" (
"id" serial PRIMARY KEY NOT NULL,
"stack_name" text NOT NULL,
"environment_id" integer,
"tag_id" integer NOT NULL,
"created_at" timestamp DEFAULT now(),
CONSTRAINT "stack_tags_stack_name_environment_id_tag_id_unique" UNIQUE("stack_name","environment_id","tag_id")
);
--> statement-breakpoint
CREATE TABLE "tags" (
"id" serial PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"color" text DEFAULT 'slate' NOT NULL,
"icon" text,
"created_at" timestamp DEFAULT now()
);
--> statement-breakpoint
CREATE UNIQUE INDEX "tags_name_unique" ON "tags" (lower("name"));--> statement-breakpoint
ALTER TABLE "container_tags" ADD CONSTRAINT "container_tags_environment_id_environments_id_fk" FOREIGN KEY ("environment_id") REFERENCES "public"."environments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "container_tags" ADD CONSTRAINT "container_tags_tag_id_tags_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "stack_tags" ADD CONSTRAINT "stack_tags_environment_id_environments_id_fk" FOREIGN KEY ("environment_id") REFERENCES "public"."environments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "stack_tags" ADD CONSTRAINT "stack_tags_tag_id_tags_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE cascade ON UPDATE no action;
Loading
Loading