Skip to content

Add monitord, a rotating CSV logger - #42

Merged
evandhoffman merged 7 commits into
mainfrom
csv-logger
Sep 5, 2026
Merged

Add monitord, a rotating CSV logger#42
evandhoffman merged 7 commits into
mainfrom
csv-logger

Conversation

@evandhoffman

Copy link
Copy Markdown
Contributor

Closes #41.

Adds monitord, a headless daemon that samples every metric on the same clock and writes rotating, human-readable CSV — the background-sampler half of the persistence roadmap, aimed at a different consumer than the app's own history: other processes that want to correlate performance with temperature or throttling.

  • MonitorCore: LogRetention (window, cadence, period) and CSVLogFormat (wide CSV, reusing the CSVExport helpers). Pure and testable.
  • MonitorLog: CSVLogSink, an actor that writes one file per cadence period (hourly for sub-day retention, daily otherwise), rolls on the boundary, and sweeps old files on a slow timer.
  • monitord: runs the existing Sampler with the sink; --dir, --retention, --interval; clean shutdown on SIGINT/SIGTERM.

The app still has no code path that reaches the filesystem: monitor does not link MonitorLog.

Format

  • Wide: one row per timestamp, one column per metric. Header written once per file from the discovered metrics.
  • Two time columns: ISO8601 (UTC) and epoch millis.
  • A metric that misses a tick leaves an empty field, never a zero.
  • Hostname is a column and part of the filename, so files from several machines sharing a directory do not clobber.

Rotation

  • One file per day, boundary on 00:00:00 localtime; hourly for sub-day windows (1h, 6h), because a daily file cannot honor a sub-day window.
  • Retention window: 1h, 6h, 24h, 48h, 3d, 5d, 7d, 14d, 30d, forever.

Verification

  • swift build && swift test — 227 tests pass (6 new).
  • swiftformat --lint — clean.
  • swift build -c release — clean.
  • Smoke-tested monitord against a temp dir: correct hourly file, hostname, timestamps, wide rows.

monitord is a headless daemon that samples every metric on the same clock
and writes rotating, human-readable CSV. It is the background-sampler half
of the persistence roadmap, aimed at a different consumer than the app's
own history: other processes that want to correlate performance with
temperature or throttling.

- MonitorCore: LogRetention (window, cadence, period) and CSVLogFormat
  (wide CSV, reusing the CSVExport helpers). Pure and testable.
- MonitorLog: CSVLogSink, an actor that writes one file per cadence period
  (hourly for sub-day retention, daily otherwise), rolls on the boundary,
  and sweeps old files on a slow timer.
- monitord: runs the existing Sampler with the sink; --dir, --retention,
  --interval; clean shutdown on SIGINT/SIGTERM.

The app still has no code path that reaches the filesystem: monitor does
not link MonitorLog. Closes #41.
@evandhoffman evandhoffman mentioned this pull request Sep 5, 2026
@evandhoffman
evandhoffman merged commit 73721aa into main Sep 5, 2026
2 checks passed
@evandhoffman
evandhoffman deleted the csv-logger branch September 5, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add sensor logging

1 participant