Files
nano_metrics/server/models/models.go
T
Gilles Soulier ff6cf1cd5e feat: métriques réseau+hardware serveur+dashboard + API /agents/{id} + iperf3
Serveur:
- Modèles Go: NetworkInterface, HardwareInfo dans Agent + AgentMetrics
- DB: migrations network_info_json + hardware_info_json dans agents
- UpsertAgent: stocke les données lentes si présentes dans le payload
- GetAgents: désérialise network_info_json + hardware_info_json
- GET /api/agents/{id}: endpoint single agent
- docker-compose: service iperf3 (port 5201)

Dashboard:
- Popup détail: section RÉSEAU (tableau interfaces: type, vitesse, MAC, WoL, iperf3)
- Popup détail: section HARDWARE (carte mère, CPU, RAM slots/type/vitesse)
- CSS: .net-table/.net-row pour le tableau réseau
- Font-size global appliqué sur html root (au lieu de body)

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

155 lines
4.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"`
NetworkInfo []NetworkInterface `json:"network_info"`
HardwareInfo *HardwareInfo `json:"hardware_info"`
}
type NetworkInterface struct {
Name string `json:"name"`
IfType string `json:"if_type"`
SpeedMbps *int64 `json:"speed_mbps"`
MAC string `json:"mac"`
WoL *bool `json:"wol"`
IperfMbps *float64 `json:"iperf_mbps"`
}
type HardwareInfo struct {
MotherboardVendor *string `json:"motherboard_vendor"`
MotherboardModel *string `json:"motherboard_model"`
CPUModel *string `json:"cpu_model"`
RAMType *string `json:"ram_type"`
RAMSpeedMHz *int64 `json:"ram_speed_mhz"`
RAMSlotsUsed *int64 `json:"ram_slots_used"`
RAMSlotsTotal *int64 `json:"ram_slots_total"`
}
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"`
NetworkInfo []NetworkInterface `json:"network_info,omitempty"`
HardwareInfo *HardwareInfo `json:"hardware_info,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"`
Version string `json:"version"`
}