Files
nano_metrics/server/models/models.go
T
Gilles Soulier a53923fd8e feat(v0.1.5): SMART multi-disques — collecte tous les disques détectés
Agent:
- SmartMetrics + champ device (nom du disque ex: sda, nvme0)
- smart: Option<Vec<SmartMetrics>> — tous les disques, pas seulement le 1er
- collect() itère /sys/block, accumule les résultats de tous les disques valides

Serveur:
- SmartMetrics.Device + Smart []SmartMetrics dans AgentMetrics
- InsertMetrics: stocke smart_json (JSON array) au lieu de colonnes plates
- GetLastMetrics: désérialise smart_json
- Migration: smart_json TEXT ajoutée

Dashboard:
- Tuile: une icône shield/triangle par disque avec tooltip incluant le nom
- Popup détail: un bouton SMART par disque (couleur ok/err)
- showSmart(agentId, diskIdx): affiche le disque sélectionné

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-23 05:23:23 +02:00

131 lines
3.8 KiB
Go

package models
type AgentMetrics struct {
Hostname string `json:"hostname"`
IP string `json:"ip"`
Status string `json:"status"`
Version string `json:"version"`
CPUPercent *float64 `json:"cpu_percent"`
MemoryUsed *int64 `json:"memory_used"`
MemoryFree *int64 `json:"memory_free"`
MemoryTotal *int64 `json:"memory_total"`
HDDUsed *int64 `json:"hdd_used"`
HDDFree *int64 `json:"hdd_free"`
HDDTotal *int64 `json:"hdd_total"`
Uptime *int64 `json:"uptime"`
NetworkRX *int64 `json:"network_rx"`
NetworkTX *int64 `json:"network_tx"`
Temperature *float64 `json:"temperature"`
Smart []SmartMetrics `json:"smart"`
}
type SmartMetrics struct {
Device string `json:"device"`
Passed bool `json:"passed"`
Temperature *int64 `json:"temperature"`
ReallocatedSectors *int64 `json:"reallocated_sectors"`
PowerOnHours *int64 `json:"power_on_hours"`
WearLevel *int64 `json:"wear_level"`
}
type Agent struct {
ID string `json:"id"`
Hostname string `json:"hostname"`
IP string `json:"ip"`
Status string `json:"status"`
LastSeen int64 `json:"last_seen"`
Version string `json:"version,omitempty"`
LastMetrics *AgentMetrics `json:"last_metrics,omitempty"`
}
type AgentConfig struct {
Metrics MetricsConfig `json:"metrics"`
Protocols ProtocolsConfig `json:"protocols"`
}
type ProtocolsConfig struct {
UDP UDPConfig `json:"udp"`
MQTT MQTTConfig `json:"mqtt"`
}
type UDPConfig struct {
Enabled bool `json:"enabled"`
}
type MQTTConfig struct {
Enabled bool `json:"enabled"`
Host string `json:"host"`
Port int `json:"port"`
TopicBase string `json:"topic_base"`
AutoDiscovery bool `json:"auto_discovery"`
BirthMessage bool `json:"birth_message"`
LastWill bool `json:"last_will"`
}
type MetricsConfig struct {
CPU MetricProto `json:"cpu"`
Memory MetricProto `json:"memory"`
Disk MetricProto `json:"disk"`
Network MetricProto `json:"network"`
Uptime MetricProto `json:"uptime"`
Temperature MetricProto `json:"temperature"`
Smart MetricProto `json:"smart"`
}
type MetricProto struct {
UDP bool `json:"udp"`
MQTT bool `json:"mqtt"`
}
type ServerConfig struct {
TileMinWidth int `json:"tile_min_width"`
FontSize int `json:"font_size"`
WarnCPU int `json:"warn_cpu"`
ErrCPU int `json:"err_cpu"`
WarnDisk int `json:"warn_disk"`
RetentionDays int `json:"retention_days"`
ChartDurationMin int `json:"chart_duration_min"`
HideOffline bool `json:"hide_offline"`
Notifications bool `json:"notifications"`
PopupDetailW int `json:"popup_detail_w"`
PopupDetailH int `json:"popup_detail_h"`
GaugeType string `json:"gauge_type"`
}
func DefaultAgentConfig() *AgentConfig {
on := MetricProto{UDP: true, MQTT: false}
return &AgentConfig{
Protocols: ProtocolsConfig{UDP: UDPConfig{Enabled: true}},
Metrics: MetricsConfig{
CPU: on,
Memory: on,
Disk: on,
Smart: on,
Uptime: on,
},
}
}
func DefaultServerConfig() ServerConfig {
return ServerConfig{
TileMinWidth: 220, FontSize: 13,
WarnCPU: 70, ErrCPU: 85, WarnDisk: 75,
RetentionDays: 30, ChartDurationMin: 30,
HideOffline: false, Notifications: true,
PopupDetailW: 560, PopupDetailH: 600,
GaugeType: "compact",
}
}
type WSMessage struct {
Type string `json:"type"`
AgentID string `json:"agent_id"`
Data interface{} `json:"data"`
}
type ServerStats struct {
CPUPercent float64 `json:"cpu_percent"`
MemUsed int64 `json:"mem_used"`
MemTotal int64 `json:"mem_total"`
}