feat(server): go.mod + config + modèles de données
Initialise le module Go github.com/user/nanometrics/server avec toutes les dépendances (SQLite, gorilla/websocket, paho.mqtt, prometheus, imaging). Ajoute config.go (Load/Default via env vars) et models.go (AgentMetrics, SmartMetrics, Agent, AgentConfig, ServerConfig, WSMessage). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package models
|
||||
|
||||
type AgentMetrics struct {
|
||||
Hostname string `json:"hostname"`
|
||||
IP string `json:"ip"`
|
||||
Status string `json:"status"`
|
||||
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 {
|
||||
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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
type WSMessage struct {
|
||||
Type string `json:"type"`
|
||||
AgentID string `json:"agent_id"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
Reference in New Issue
Block a user