Update CLAUDE.md with correct ZMQ sender architecture

This commit is contained in:
Christoffer Martinsson 2025-11-27 22:59:38 +01:00
parent 01e1f33b66
commit 43dd5a901a

View File

@ -207,10 +207,16 @@ Every 1 second:
- Recommended: Slow (60-300s): Disk, Systemd
- **Independent tasks**: Each collector spawned as separate tokio task in `Agent::new()`
- **Cache updates**: Collectors acquire write lock → update → release immediately
- **ZMQ sender**: Main loop reads cache every `collection_interval_seconds` and broadcasts
- **Notification check**: Runs every `notifications.check_interval_seconds`
- **Lock strategy**: Short-lived write locks prevent blocking, read locks for transmission
- **Stale data**: Acceptable for slow-changing metrics (SMART data, disk usage)
- **ZMQ sender**: Dedicated OS thread with own publisher socket, uses `try_read()` to avoid blocking
- **Non-blocking reads**: `try_read()` never blocks - sends previous data if cache is locked
- **Notification check**: Runs every `notifications.check_interval_seconds` in main loop
- **Lock strategy**: Short-lived write locks, non-blocking reads for transmission
- **Stale data**: Acceptable for slow-changing metrics AND when collector holds write lock
**Threading Model:**
- Main thread: tokio runtime for command handling and notifications
- Collector threads: 7 independent tokio tasks updating shared cache
- ZMQ sender thread: Dedicated OS thread (ZMQ sockets not thread-safe) with lock-free reads
**Configuration (NixOS):**
All intervals and timeouts configurable in `services/cm-dashboard.nix`:
@ -232,9 +238,10 @@ Command Timeouts (prevent resource leaks from hung commands):
- `collectors.network.command_timeout_seconds` (default: 10s) - ip route, ip addr
**Code Locations:**
- agent/src/agent.rs:59-133 - Collector task spawning
- agent/src/agent.rs:151-179 - Independent collector task runner
- agent/src/agent.rs:199-207 - ZMQ sender in main loop
- agent/src/agent.rs:69-144 - Collector task spawning with configured intervals
- agent/src/agent.rs:162-190 - Independent collector task runner
- agent/src/agent.rs:202-249 - ZMQ sender in dedicated OS thread with try_read()
- agent/src/agent.rs:251-264 - Main loop (commands and notifications only)
### Maintenance Mode