up
This commit is contained in:
+52
-24
@@ -46,16 +46,16 @@ func loadConfig(path string) (*Config, error) {
|
||||
// ── Métricas ──────────────────────────────────────────────────────────────────
|
||||
|
||||
type Metricas struct {
|
||||
Hostname string `json:"hostname"`
|
||||
OS string `json:"os"`
|
||||
Arch string `json:"arch"`
|
||||
Uptime uint64 `json:"uptime_seg"`
|
||||
UptimeStr string `json:"uptime"`
|
||||
RAM RAMInfo `json:"ram"`
|
||||
CPU CPUInfo `json:"cpu"`
|
||||
Disco DiscoInfo `json:"disco"`
|
||||
LoadAvg LoadInfo `json:"load_avg"`
|
||||
ReportadoEn string `json:"reportado_en"`
|
||||
Hostname string `json:"hostname"`
|
||||
OS string `json:"os"`
|
||||
Arch string `json:"arch"`
|
||||
Uptime uint64 `json:"uptime_seg"`
|
||||
UptimeStr string `json:"uptime"`
|
||||
RAM RAMInfo `json:"ram"`
|
||||
CPU CPUInfo `json:"cpu"`
|
||||
Discos []DiscoInfo `json:"discos"`
|
||||
LoadAvg LoadInfo `json:"load_avg"`
|
||||
ReportadoEn string `json:"reportado_en"`
|
||||
}
|
||||
|
||||
type RAMInfo struct {
|
||||
@@ -136,19 +136,47 @@ func collectMetrics() (*Metricas, error) {
|
||||
m.CPU.Porcentaje = round2(pcts[0])
|
||||
}
|
||||
|
||||
// Disco (raíz /)
|
||||
root := "/"
|
||||
if runtime.GOOS == "windows" {
|
||||
root = "C:\\"
|
||||
}
|
||||
if d, err := disk.Usage(root); err == nil {
|
||||
// Discos: todas las particiones físicas/reales
|
||||
if parts, err := disk.Partitions(false); err == nil {
|
||||
gb := 1024.0 * 1024 * 1024
|
||||
m.Disco = DiscoInfo{
|
||||
TotalGB: round2(float64(d.Total) / gb),
|
||||
UsadoGB: round2(float64(d.Used) / gb),
|
||||
LibreGB: round2(float64(d.Free) / gb),
|
||||
Porcentaje: round2(d.UsedPercent),
|
||||
Ruta: root,
|
||||
skipFSTypes := map[string]bool{
|
||||
"proc": true, "sysfs": true, "tmpfs": true, "devtmpfs": true,
|
||||
"devpts": true, "cgroup": true, "cgroup2": true, "overlay": true,
|
||||
"hugetlbfs": true, "mqueue": true, "pstore": true, "securityfs": true,
|
||||
"debugfs": true, "tracefs": true, "autofs": true, "fusectl": true,
|
||||
"configfs": true, "efivarfs": true, "bpf": true, "rpc_pipefs": true,
|
||||
"squashfs": true, "ramfs": true, "nsfs": true, "none": true,
|
||||
}
|
||||
for _, p := range parts {
|
||||
if skipFSTypes[p.Fstype] {
|
||||
continue
|
||||
}
|
||||
if d, err := disk.Usage(p.Mountpoint); err == nil {
|
||||
m.Discos = append(m.Discos, DiscoInfo{
|
||||
TotalGB: round2(float64(d.Total) / gb),
|
||||
UsadoGB: round2(float64(d.Used) / gb),
|
||||
LibreGB: round2(float64(d.Free) / gb),
|
||||
Porcentaje: round2(d.UsedPercent),
|
||||
Ruta: p.Mountpoint,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fallback: si no se encontraron particiones, usar raíz
|
||||
if len(m.Discos) == 0 {
|
||||
root := "/"
|
||||
if runtime.GOOS == "windows" {
|
||||
root = "C:\\"
|
||||
}
|
||||
if d, err := disk.Usage(root); err == nil {
|
||||
gb := 1024.0 * 1024 * 1024
|
||||
m.Discos = []DiscoInfo{{
|
||||
TotalGB: round2(float64(d.Total) / gb),
|
||||
UsadoGB: round2(float64(d.Used) / gb),
|
||||
LibreGB: round2(float64(d.Free) / gb),
|
||||
Porcentaje: round2(d.UsedPercent),
|
||||
Ruta: root,
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,8 +276,8 @@ func main() {
|
||||
if err := sendHeartbeat(cfg, m); err != nil {
|
||||
log.Printf("⚠️ Error enviando heartbeat: %v", err)
|
||||
} else {
|
||||
log.Printf("✅ Heartbeat enviado | RAM: %.1f%% | CPU: %.1f%% | Disco: %.1f%%",
|
||||
m.RAM.Porcentaje, m.CPU.Porcentaje, m.Disco.Porcentaje)
|
||||
log.Printf("✅ Heartbeat enviado | RAM: %.1f%% | CPU: %.1f%% | Discos: %d",
|
||||
m.RAM.Porcentaje, m.CPU.Porcentaje, len(m.Discos))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user