Redesign, cut CPU use ~70%, and add persistent history with UPS power events #1

Merged
sebastjan merged 11 commits from redesign-perf-history into main 2026-10-31 21:03:17 +01:00
Owner

Summary

Three changes, built in parallel and merged here:

Redesign: a printed instrument panel

  • New look with no cards, shadows or pills. Content sits in sections divided by thin lines, on a warm paper (light) or graphite (dark) background.
  • Inter for text and numbers; Martian Mono (self-hosted 32 KB subset, OFL) for captions and axis ticks. Cal Sans is removed.
  • Larger, calmer type: 15px body text and one 40px figure per view. Weights stay between 400 and 500.
  • Charts have real axes and a crosshair tooltip (also usable with arrow keys). Two data colours, checked with the dataviz palette rules in both themes.
  • A pass to remove clutter: each reading appears once, there are fewer labels and dividing lines, and more space. The UPS events read as "On battery → mains 11:35", with a quiet "lowest 81%" line underneath.
  • Desktop and mobile layouts, light/dark themes, the public view and the PWA are kept. DESIGN.md is rewritten.

Performance: production uses ~18–22% CPU; this branch uses ~5–6%

  • docker ps now runs with --size=false. Without it, Docker computed every container's disk size on each call (334 ms → 27 ms).
  • One long-running docker stats stream replaces a new docker stats process every second.
  • sysinfo 0.33 → 0.38: it no longer refreshes every thread as a process (~3,300 → ~840 entries) and no longer uses a worker pool.
  • Sensors are read on their own thread every 5 s.
  • Each snapshot is encoded once for admins and once for the public, and shared by all SSE clients and /api/metrics. With 20 clients connected, CPU drops from 39% to 6%. Public-access filtering is unchanged, and a new test checks it.
  • A stopped container in a project log view now waits on docker events instead of restarting docker logs every second.

Persistent history and UPS power events

  • src/history.rs stores samples at three levels of detail: raw for 1 h, 1-minute averages for 7 d, 15-minute averages for 90 d. Files are fixed-size records under about 2 MB, saved every 60 s and on SIGTERM, and survive a half-written last record.
  • UPS power events are recorded: switch to battery → back on mains, with duration, start/lowest/end charge, low-battery flag and flap count, plus periods when the UPS was unavailable. The first reading after startup is a baseline, never an event, and the last state is saved so switches across a restart are still caught.
  • GET /api/history?range=1h|6h|24h|7d|30d|90d and GET /api/ups/events. Both follow config/public-access.json.
  • The Overview charts can switch between live and stored ranges. The UPS page shows a power-source band, charge/load/runtime charts and an event timeline.
  • Compose adds a history-data:/app/data volume (HISTORY_DIR).

Also

  • compose.dev.yml runs a separate dev preview (its own image, alias, history volume, and a read-only Compose mount).

Behaviour changes

  • The process list and process count no longer include threads.
  • Temperatures and fans update every 5 s instead of every second.
  • Container status refreshes every 2 s.

Testing

  • cargo fmt --check and cargo test pass: 21 tests, including the new history, transition, persistence and public-filtering tests.
  • All tests/*.test.js pass, including the new history.test.js.
  • A Docker build on musl works. Data persisted across a restart, and SIGTERM saves history.
  • Dev preview at https://system-dev.labss.me (Relay, members only). Screenshots at 1440/1280/390 in both themes; no page overflows horizontally.

Deploy notes

docker compose up -d --build creates the new history-data volume. History starts empty, and power events begin recording after the first reading.

🤖 Generated with Claude Code

## Summary Three changes, built in parallel and merged here: ### Redesign: a printed instrument panel - New look with no cards, shadows or pills. Content sits in sections divided by thin lines, on a warm paper (light) or graphite (dark) background. - Inter for text and numbers; Martian Mono (self-hosted 32 KB subset, OFL) for captions and axis ticks. Cal Sans is removed. - Larger, calmer type: 15px body text and one 40px figure per view. Weights stay between 400 and 500. - Charts have real axes and a crosshair tooltip (also usable with arrow keys). Two data colours, checked with the `dataviz` palette rules in both themes. - A pass to remove clutter: each reading appears once, there are fewer labels and dividing lines, and more space. The UPS events read as "On battery → mains 11:35", with a quiet "lowest 81%" line underneath. - Desktop and mobile layouts, light/dark themes, the public view and the PWA are kept. `DESIGN.md` is rewritten. ### Performance: production uses ~18–22% CPU; this branch uses ~5–6% - `docker ps` now runs with `--size=false`. Without it, Docker computed every container's disk size on each call (334 ms → 27 ms). - One long-running `docker stats` stream replaces a new `docker stats` process every second. - sysinfo 0.33 → 0.38: it no longer refreshes every thread as a process (~3,300 → ~840 entries) and no longer uses a worker pool. - Sensors are read on their own thread every 5 s. - Each snapshot is encoded once for admins and once for the public, and shared by all SSE clients and `/api/metrics`. With 20 clients connected, CPU drops from 39% to 6%. Public-access filtering is unchanged, and a new test checks it. - A stopped container in a project log view now waits on `docker events` instead of restarting `docker logs` every second. ### Persistent history and UPS power events - `src/history.rs` stores samples at three levels of detail: raw for 1 h, 1-minute averages for 7 d, 15-minute averages for 90 d. Files are fixed-size records under about 2 MB, saved every 60 s and on SIGTERM, and survive a half-written last record. - UPS power events are recorded: switch to battery → back on mains, with duration, start/lowest/end charge, low-battery flag and flap count, plus periods when the UPS was unavailable. The first reading after startup is a baseline, never an event, and the last state is saved so switches across a restart are still caught. - `GET /api/history?range=1h|6h|24h|7d|30d|90d` and `GET /api/ups/events`. Both follow `config/public-access.json`. - The Overview charts can switch between live and stored ranges. The UPS page shows a power-source band, charge/load/runtime charts and an event timeline. - Compose adds a `history-data:/app/data` volume (`HISTORY_DIR`). ### Also - `compose.dev.yml` runs a separate dev preview (its own image, alias, history volume, and a read-only Compose mount). ## Behaviour changes - The process list and process count no longer include threads. - Temperatures and fans update every 5 s instead of every second. - Container status refreshes every 2 s. ## Testing - `cargo fmt --check` and `cargo test` pass: 21 tests, including the new history, transition, persistence and public-filtering tests. - All `tests/*.test.js` pass, including the new `history.test.js`. - A Docker build on musl works. Data persisted across a restart, and SIGTERM saves history. - Dev preview at https://system-dev.labss.me (Relay, members only). Screenshots at 1440/1280/390 in both themes; no page overflows horizontally. ## Deploy notes `docker compose up -d --build` creates the new `history-data` volume. History starts empty, and power events begin recording after the first reading. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Replace the Cal-style dashboard with a dense, calm instrument panel:
neutral greys, one accent (charts/focus), semantic colour only for
state, hairline panels with no shadows or gradients, and readings set
large in Inter tabular figures.

- Rewrite style.css from scratch on a small token set (light/dark),
  and reformat index.html into readable, sectioned markup.
- Overview: key-figure strip, activity chart, host facts, Compose
  summary, network sparklines, UPS summary.
- Containers: single project list with aligned usage and actions,
  separate Stopped and Not deployed panels; tables become label/value
  cards on mobile.
- Charts draw a flat fill in currentColor so CSS picks the series
  colour (only app.js change).
- Add empty, styled mounts #overview-history and #ups-history plus
  .chart-card, .history-grid and .timeline-row classes for the
  history UI.
- Drop Cal Sans (font, licence, asset route); Inter is the only face.
- Rewrite DESIGN.md; update README, NOTICE, demo fixtures and
  screenshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- src/history.rs: tiered history (raw ~1 s for 1 h, 1-minute averages for
  7 d, 15-minute averages for 90 d) kept in bounded in-memory rings and
  mirrored to fixed-record files in HISTORY_DIR. Rows are appended once a
  minute and on SIGTERM/SIGINT, and files are compacted atomically, so disk
  use stays under ~2 MB. Partial buckets are rebuilt from raw rows on start.
- UPS power events derived from OL/OB/LB status flags: switch to battery and
  back to mains with duration, start/min/end charge, low-battery time, and
  flap count (returns to battery within 60 s reopen the outage), plus
  debounced (30 s) unavailable periods. Last known state is persisted so a
  transition across a restart is still recorded; first readings are only a
  baseline.
- GET /api/history?range=1h|6h|24h|7d|30d|90d (columnar, <=720 points) and
  GET /api/ups/events, filtered by the public-access options for non-admins.
- static/history.js: UPS power history charts and event list (#ups-history)
  and an overview range picker (#overview-history) that switches existing
  overview charts to stored history.
- compose.yml/Dockerfile: history-data volume at /app/data, HISTORY_DIR.
- Demo data, README, Rust and node tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured with a private replica of the production container on this host
(same mounts and capabilities): idle 17-18% -> 6.0%; with 20 SSE clients
39.2% -> 6.1%; extra dockerd CPU caused by Hostwatch ~20% -> ~2%.

- docker ps used --format '{{json .}}', which makes the CLI request
  container sizes, so the daemon walked every container's layers on each
  call (334 ms vs 27 ms). Pass --size=false (collector and project logs).
- Replace a `docker stats --no-stream` per tick (2.1 s, ~0.5 s dockerd
  CPU each) with one long-lived streaming `docker stats`, publishing only
  complete refreshes. `docker ps` now runs every 2 s instead of ~3 s.
- sysinfo refreshed every thread as a process (~3300 entries instead of
  ~840) on a 16-thread rayon pool, and re-read exe links. Upgrade to 0.38
  (same API), drop default features (no rayon), refresh only cpu, memory
  and disk usage without tasks. Process list and count now exclude threads.
- Rank processes before building JSON for the 100 published rows.
- hwmon reads (it87 fans, drivetemp, nvme) took 35-330 ms per tick and
  stretched the collector period. Poll them on their own thread every 5 s.
  The collector now ticks on a steady 1 s interval.
- Serialise each snapshot once per audience (admin/public) and share it
  across SSE and /api/metrics clients instead of filtering and encoding per
  client per tick. Output bytes are unchanged; a test checks that both
  encodings match visible_metrics.
- Stopped project members in a log stream re-ran `docker logs` and
  `docker inspect` every second. They now wait on one idle `docker events`
  stream and reattach on start, ending when the container is destroyed.
- Frontend: freeze log records so Alpine doesn't deep-proxy up to 1500
  rows when the log filter runs on every batch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adapt the history UI to the redesign's panels, chart cards, timeline rows
and segmented range picker; feed history from the raw snapshot channel
now that SSE uses pre-encoded frames.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the card dashboard with ruled sections on warm paper (light) or deep
graphite (dark). Text is set larger (15px body), with one moderate hero figure
per view and lighter weights.

- Pair Inter with Martian Mono, a self-hosted 32 KB Latin subset under the OFL
  and served from the asset whitelist, for captions, axis ticks and timestamps.
- Overview: an asymmetric 2:1 spread. Activity holds the CPU hero, memory, a
  chart with real axes, a crosshair tooltip (also keyboard) and per-core
  columns. Readings is a ruled ledger: containers split bar, hottest sensor
  scale, network sparklines and UPS.
- Charts: hairline grids, 2px lines, end markers and a 10% wash. The series
  colours (vermilion, heather) pass the dataviz palette checks in both themes.
- UPS: a battery hero with a 0-100% scale, a ruled readings list, a
  power-source band (mains rail, battery and outage blocks), small-multiple
  history charts with axes and crosshair readouts, and a railed event timeline
  that shows the lowest charge reached in each event.
- Keep the Alpine state layer; add chart axis and hover helpers. Update theme
  colours, the manifest, DESIGN.md, README, NOTICE and the screenshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the instrument-panel concept, palette and type, but make every element
earn its place.

- Overview: drop the chart note and the per-core strip. Range tabs are now
  Live/1h/24h/7d/30d (UPS keeps 6h and 90d). Load is shown only under CPU,
  host facts are identity only, and the Admin badge becomes a tooltip on Live.
  Readings are space-separated groups; UPS shows battery %, status and one
  runtime line.
- UPS: show each reading once in a quiet two-column list. Drop the tick row,
  "Estimated at current load" and the duplicate output and rated power.
  History charts keep only max/zero ticks and a fainter wash under the shared
  band axis. Event rows read "On battery → mains 11:35", with a quiet
  "lowest 81% · low battery · flapped 1×" line instead of bars and boxed tags.
- Everywhere: mono capitals only on the eyebrow and figure captions;
  sentence-case column heads; one rule per section, with spacing instead of
  rules in facts, ledgers, hardware rows and timelines. On mobile, project
  actions appear when a project is opened and secondary table columns are
  hidden.
- Update DESIGN.md, the history tests and the screenshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tested against a realistic fixture in docs/demo-data.js: 64 containers with a
19-service project and digest-only images, 16 core sensors, 7 drives, 100
processes, 10 mounts and 16 interfaces.

- Containers: rows are single-line (name with a short image name, one-line
  status such as "Up 21 hours", CPU, memory with share in the tooltip).
  Net I/O, Block I/O and PIDs move behind a "More columns" toggle that is
  remembered in localStorage. Project and row actions become quiet text
  buttons, shown on hover or keyboard focus with a precise pointer and always
  reachable on touch.
- Temperatures: one row per device leading with the hottest reading. Small
  devices list other sensors as quiet text; CPU cores summarise as a range
  and average with a lightness strip, plus "Show all" for per-core values.
  Driver names move into tooltips, and warn colour appears only when warm.
- Hardware: a CPU summary row (overall %, per-core strip, busiest core, MHz
  range) with the per-core table on demand; memory shows "used of total".
- Processes: top 20 by default with "Show all"; I/O and state are optional
  columns. Storage and network apply the same toggle, and virtual interfaces
  are on demand.
- Tables keep the last visible column flush; content widens to 1560px.
- Update DESIGN.md and regenerate screenshots from the denser fixture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Containers stay as they were. Elsewhere, undo the parts of the last pass that
hid cheap, useful detail.

- Temperatures: CPU cores keep the summary line ("16 sensors · 44-66 °C ·
  avg 57") and always show a compact grid of every core (label, short bar
  shaded by temperature, value). No toggle. Device rows gain a thin, quiet
  meter beside the hottest reading (hidden on phones, where long names now
  wrap).
- Hardware: the per-core usage table is always visible under a calmer summary
  row, with tighter rows.
- Overview: a thin per-core strip returns under the Activity chart with only
  a "Per core" caption.
- Network: list every interface when there are eight or fewer; keep the
  virtual-interface toggle for busy hosts. "More columns" stays for the wide
  tables.
- Update DESIGN.md and the screenshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sebastjan/hostwatch!1
No description provided.