- agent-linux/: Kompletter Linux/Proxmox RMM Agent - Collectors: CPU, Memory, Disk, Network, Services, Updates, Proxmox (VMs, Container, Storage, ZFS), Backups - Backup Collector: Jobs nach Node gefiltert (Cluster-aware) - WebSocket: Tunnel-Support, writeMux fuer stabile Verbindungen - Systemd Service Template - updater/: Plattform-unabhaengiger Updater (FreeBSD + Linux) - runtime.GOOS erkennt Plattform automatisch - FreeBSD: /usr/local/rmm/, service rmm_agent - Linux: /usr/local/bin/, /etc/rmm/, systemctl rmm-agent - Firmware-Download mit ?platform= Parameter - frontend/: Proxmox-Bereich - ProxmoxServers.jsx: Eigene Seite fuer PVE Server mit VM/CT Counts - ProxmoxPanel.jsx: Detail-Panel mit Uebersicht, VMs, Container, Storage, ZFS, Tunnel, Dienste, Updates, Backups - Agents.jsx: Filtert Linux-Agents raus (nur OPNsense) - Sidebar: Proxmox Navigationspunkt - Installationsanleitung mit rmm-agent-linux + rmm-updater-linux - backend: Platform-Feld fuer Agents, Firmware multi-platform
70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package collector
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type MemoryInfo struct {
|
|
TotalBytes int64
|
|
UsedBytes int64
|
|
FreeBytes int64
|
|
}
|
|
|
|
func CollectMemory() MemoryInfo {
|
|
mem := MemoryInfo{}
|
|
|
|
data, err := os.ReadFile("/proc/meminfo")
|
|
if err != nil {
|
|
return mem
|
|
}
|
|
|
|
lines := strings.Split(string(data), "\n")
|
|
values := make(map[string]int64)
|
|
|
|
for _, line := range lines {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" {
|
|
continue
|
|
}
|
|
|
|
parts := strings.Fields(line)
|
|
if len(parts) < 2 {
|
|
continue
|
|
}
|
|
|
|
key := strings.TrimSuffix(parts[0], ":")
|
|
valueStr := parts[1]
|
|
|
|
// Wert in kB, konvertiere zu Bytes
|
|
if value, err := strconv.ParseInt(valueStr, 10, 64); err == nil {
|
|
values[key] = value * 1024 // kB zu Bytes
|
|
}
|
|
}
|
|
|
|
// Basis-Werte
|
|
memTotal := values["MemTotal"]
|
|
memFree := values["MemFree"]
|
|
memAvailable := values["MemAvailable"]
|
|
buffers := values["Buffers"]
|
|
cached := values["Cached"]
|
|
|
|
mem.TotalBytes = memTotal
|
|
|
|
// Verfügbarer Speicher: Nutze MemAvailable falls vorhanden, sonst berechne
|
|
if memAvailable > 0 {
|
|
mem.FreeBytes = memAvailable
|
|
} else {
|
|
// Fallback: Free + Buffers + Cached (grobe Schätzung)
|
|
mem.FreeBytes = memFree + buffers + cached
|
|
}
|
|
|
|
// Benutzter Speicher = Total - Free
|
|
if mem.FreeBytes > mem.TotalBytes {
|
|
mem.FreeBytes = mem.TotalBytes
|
|
}
|
|
mem.UsedBytes = mem.TotalBytes - mem.FreeBytes
|
|
|
|
return mem
|
|
} |