Spaces:
Running
Running
File size: 788 Bytes
750bbe6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | package xsysinfo
import (
"github.com/mudler/memory"
)
// SystemRAMInfo contains system RAM usage information
type SystemRAMInfo struct {
Total uint64 `json:"total"`
Used uint64 `json:"used"`
Free uint64 `json:"free"`
Available uint64 `json:"available"`
UsagePercent float64 `json:"usage_percent"`
}
// GetSystemRAMInfo returns real-time system RAM usage
func GetSystemRAMInfo() (*SystemRAMInfo, error) {
total := memory.TotalMemory()
free := memory.AvailableMemory()
used := total - free
usagePercent := 0.0
if total > 0 {
usagePercent = float64(used) / float64(total) * 100
}
return &SystemRAMInfo{
Total: total,
Used: used,
Free: free,
Available: total - used,
UsagePercent: usagePercent,
}, nil
}
|