Implement complete structured data architecture
All checks were successful
Build and Release / build-and-release (push) Successful in 2m10s

Replace fragile string-based metrics with type-safe JSON data structures.
Agent converts all metrics to structured data, dashboard processes typed fields.

Changes:
- Add AgentData struct with CPU, memory, storage, services, backup fields
- Replace string parsing with direct field access throughout system
- Maintain UI compatibility via temporary metric bridge conversion
- Fix NVMe temperature display and eliminate string parsing bugs
- Update protocol to support structured data transmission over ZMQ
- Comprehensive metric type coverage: CPU, memory, storage, services, backup

Version bump to 0.1.131
This commit is contained in:
2025-11-23 21:32:00 +01:00
parent 41ded0170c
commit adf3b0f51c
14 changed files with 926 additions and 106 deletions

113
CLAUDE.md
View File

@@ -59,11 +59,85 @@ hostname2 = [
## Core Architecture Principles
### Individual Metrics Philosophy
- Agent collects individual metrics, dashboard composes widgets
- Each metric collected, transmitted, and stored individually
- Agent calculates status for each metric using thresholds
- Dashboard aggregates individual metric statuses for widget status
### Structured Data Architecture (Planned Migration)
Current system uses string-based metrics with complex parsing. Planning migration to structured JSON data to eliminate fragile string manipulation.
**Current (String Metrics):**
- Agent sends individual metrics with string names like `disk_nvme0n1_temperature`
- Dashboard parses metric names with underscore counting and string splitting
- Complex and error-prone metric filtering and extraction logic
**Target (Structured Data):**
```json
{
"hostname": "cmbox",
"agent_version": "v0.1.130",
"timestamp": 1763926877,
"system": {
"cpu": {
"load_1min": 3.50,
"load_5min": 3.57,
"load_15min": 3.58,
"frequency_mhz": 1500,
"temperature_celsius": 45.2
},
"memory": {
"usage_percent": 25.0,
"total_gb": 23.3,
"used_gb": 5.9,
"swap_total_gb": 10.7,
"swap_used_gb": 0.99,
"tmpfs": [
{"mount": "/tmp", "usage_percent": 15.0, "used_gb": 0.3, "total_gb": 2.0}
]
},
"storage": {
"drives": [
{
"name": "nvme0n1",
"health": "PASSED",
"temperature_celsius": 29.0,
"wear_percent": 1.0,
"filesystems": [
{"mount": "/", "usage_percent": 24.0, "used_gb": 224.9, "total_gb": 928.2}
]
}
],
"pools": [
{
"name": "srv_media",
"mount": "/srv/media",
"type": "mergerfs",
"health": "healthy",
"usage_percent": 63.0,
"used_gb": 2355.2,
"total_gb": 3686.4,
"data_drives": [
{"name": "sdb", "temperature_celsius": 24.0}
],
"parity_drives": [
{"name": "sdc", "temperature_celsius": 24.0}
]
}
]
}
},
"services": [
{"name": "sshd", "status": "active", "memory_mb": 4.5, "disk_gb": 0.0}
],
"backup": {
"status": "completed",
"last_run": 1763920000,
"next_scheduled": 1764006400,
"total_size_gb": 150.5,
"repository_health": "ok"
}
}
```
- Agent sends structured JSON over ZMQ
- Dashboard accesses data directly: `data.system.storage.drives[0].temperature_celsius`
- Type safety eliminates all parsing bugs
### Maintenance Mode
- Agent checks for `/tmp/cm-maintenance` file before sending notifications
@@ -293,12 +367,33 @@ Keep responses concise and focused. Avoid extensive implementation summaries unl
- ✅ "Restructure storage widget with improved layout"
- ✅ "Update CPU thresholds to production values"
## Planned Architecture Migration
### Phase 1: Structured Data Types (Shared Crate)
- Create Rust structs matching target JSON structure
- Replace `Metric` enum with typed data structures
- Add serde serialization/deserialization
### Phase 2: Agent Refactor
- Update collectors to return typed structs instead of `Vec<Metric>`
- Remove string metric name generation
- Send structured JSON over ZMQ
### Phase 3: Dashboard Refactor
- Replace metric parsing logic with direct field access
- Remove `extract_pool_name()`, `extract_drive_name()`, underscore counting
- Widgets access `data.system.storage.drives[0].temperature_celsius`
### Phase 4: Migration & Cleanup
- Support both formats during transition
- Gradual rollout with backward compatibility
- Remove legacy string metric system
## Implementation Rules
1. **Individual Metrics**: Each metric is collected, transmitted, and stored individually
2. **Agent Status Authority**: Agent calculates status for each metric using thresholds
3. **Dashboard Composition**: Dashboard widgets subscribe to specific metrics by name
4. **Status Aggregation**: Dashboard aggregates individual metric statuses for widget status
1. **Agent Status Authority**: Agent calculates status for each metric using thresholds
2. **Dashboard Composition**: Dashboard widgets subscribe to specific metrics by name
3. **Status Aggregation**: Dashboard aggregates individual metric statuses for widget status
**NEVER:**
- Copy/paste ANY code from legacy implementations