From 9ae526302b40c36e4413b1e9ab11ece7c3c3fc82 Mon Sep 17 00:00:00 2001
From: Ilker Manap
Date: Mon, 28 Sep 2026 23:30:01 +0200
Subject: [PATCH] Label chart axes in binary sizes and small percents, and
windows in words
A bytes axis read "20.0BB" - compact's billion with a B after it - and
a quiet node's CPU axis read 0% all the way up. Sizes are now binary like
every other on these pages, a percent under ten keeps a decimal, and a
window of an hour is "the last hour" rather than "1h0m0s".
Co-Authored-By: Claude Opus 5.5 (1M context)
---
internal/web/dashcharts.go | 2 +-
internal/web/node_page.go | 2 +-
internal/web/templates/node.html | 2 +-
internal/web/timeseries.go | 9 ++++++-
internal/web/timeseries_test.go | 17 +++++++++++++
internal/web/web.go | 41 ++++++++++++++++++++++----------
6 files changed, 57 insertions(+), 16 deletions(-)
diff --git a/internal/web/dashcharts.go b/internal/web/dashcharts.go
index 369a514..5821e63 100644
--- a/internal/web/dashcharts.go
+++ b/internal/web/dashcharts.go
@@ -75,7 +75,7 @@ func LoadFleetCharts(ctx context.Context, h History, window time.Duration,
// size and a bigger response to parse on every page load.
step := window / 60
- out := &FleetCharts{Window: window.String()}
+ out := &FleetCharts{Window: windowWord(window)}
for _, p := range fleetPanels {
series, err := h.RangeQuery(ctx, p.expr, p.nameBy, window, step)
if err != nil {
diff --git a/internal/web/node_page.go b/internal/web/node_page.go
index e33ec44..59f8303 100644
--- a/internal/web/node_page.go
+++ b/internal/web/node_page.go
@@ -126,7 +126,7 @@ func loadNodeCharts(ctx context.Context, h History, node string, replicas []stri
window time.Duration, log *slog.Logger,
) *nodeCharts {
step := window / 60
- out := &nodeCharts{Window: window.String()}
+ out := &nodeCharts{Window: windowWord(window)}
quoted := fmt.Sprintf("%q", node)
for _, p := range nodePanels {
series, err := h.RangeQuery(ctx, fmt.Sprintf(p.expr, quoted), p.nameBy, window, step)
diff --git a/internal/web/templates/node.html b/internal/web/templates/node.html
index 0f40d56..66f4444 100644
--- a/internal/web/templates/node.html
+++ b/internal/web/templates/node.html
@@ -9,7 +9,7 @@
{{.Node.ID}}
{{.Node.State}}
{{with .Node.OS}} · {{.}}{{end}}{{with .Node.MgmtAddr}} · {{.}}{{end}}
- · last seen {{or .Node.LastSeenAgo "never"}} ago · logs · cluster
+ · last seen {{or .Node.LastSeenAgo "never"}} ago · logs
{{if .OnAdminListener}}{{else}}{{template "nav" .Nav}}{{end}}
diff --git a/internal/web/timeseries.go b/internal/web/timeseries.go
index 4d01533..8e2dfa9 100644
--- a/internal/web/timeseries.go
+++ b/internal/web/timeseries.go
@@ -244,6 +244,11 @@ func niceCeiling(v float64) float64 {
func formatValue(v float64, unit string) string {
switch unit {
case "%":
+ // A decimal below ten, where whole percents would print a quiet
+ // machine's axis as 0%, 0%, 0%.
+ if v != 0 && v*100 < 10 {
+ return fmt.Sprintf("%.1f%%", v*100)
+ }
return fmt.Sprintf("%.0f%%", v*100)
case "s":
if v < 1 {
@@ -251,7 +256,9 @@ func formatValue(v float64, unit string) string {
}
return fmt.Sprintf("%.1fs", v)
case "bytes":
- return compact(v) + "B"
+ // Binary, like every other size on these pages. compact's own
+ // suffixes are for counts, and on bytes read as "20.0BB".
+ return strings.Replace(humanBytes(int64(v)), " ", "", 1)
default:
return compact(v)
}
diff --git a/internal/web/timeseries_test.go b/internal/web/timeseries_test.go
index 2d515bd..2da8db2 100644
--- a/internal/web/timeseries_test.go
+++ b/internal/web/timeseries_test.go
@@ -196,3 +196,20 @@ func TestAUsageLegendGivesTotalsNotTheLastSlice(t *testing.T) {
t.Errorf("legend = %v, expected the totals", got)
}
}
+
+func TestChartAxesReadAsSizesAndSmallPercents(t *testing.T) {
+ // compact's suffixes are for counts: on bytes they read as "20.0BB".
+ if got := formatValue(20e9, "bytes"); got != "18.6GiB" {
+ t.Errorf("20e9 bytes = %q", got)
+ }
+ // A quiet machine is not 0%, 0%, 0% up its axis.
+ if got := formatValue(0.005, "%"); got != "0.5%" {
+ t.Errorf("0.005 = %q", got)
+ }
+ if got := formatValue(0.62, "%"); got != "62%" {
+ t.Errorf("0.62 = %q", got)
+ }
+ if got := windowWord(time.Hour); got != "hour" {
+ t.Errorf("an hour reads %q", got)
+ }
+}
diff --git a/internal/web/web.go b/internal/web/web.go
index 0eb3b66..4467090 100644
--- a/internal/web/web.go
+++ b/internal/web/web.go
@@ -101,18 +101,7 @@ var funcs = template.FuncMap{
// shows. Binary units because that is what `ls -lh` and every disk-full
// message on the host will say, and a page that disagrees with the shell
// about the size of the same file starts an argument about neither.
- "bytes": func(n int64) string {
- const unit = 1024
- if n < unit {
- return fmt.Sprintf("%d B", n)
- }
- div, exp := int64(unit), 0
- for v := n / unit; v >= unit; v /= unit {
- div *= unit
- exp++
- }
- return fmt.Sprintf("%.1f %ciB", float64(n)/float64(div), "KMGTPE"[exp])
- },
+ "bytes": humanBytes,
// dict lets one chart template be called with named arguments. Go
// templates pass a single value, and four charts differing in three
// strings each is four copies of the same markup otherwise.
@@ -256,3 +245,31 @@ func ago(t time.Time) string {
return unit(int(d.Hours()/24/30+0.5), "month")
}
}
+
+// humanBytes writes a size in binary units, the way the shell does.
+func humanBytes(n int64) string {
+ const unit = 1024
+ if n < unit {
+ return fmt.Sprintf("%d B", n)
+ }
+ div, exp := int64(unit), 0
+ for v := n / unit; v >= unit; v /= unit {
+ div *= unit
+ exp++
+ }
+ return fmt.Sprintf("%.1f %ciB", float64(n)/float64(div), "KMGTPE"[exp])
+}
+
+// windowWord names a chart window the way a sentence would: "hour", "6
+// hours", "30 minutes", rather than Go's 1h0m0s.
+func windowWord(d time.Duration) string {
+ switch {
+ case d == time.Hour:
+ return "hour"
+ case d%time.Hour == 0:
+ return fmt.Sprintf("%d hours", int(d.Hours()))
+ case d%time.Minute == 0:
+ return fmt.Sprintf("%d minutes", int(d.Minutes()))
+ }
+ return d.String()
+}