Files
LocalAI/pkg/xsysinfo/memory.go
Ettore Di Giacinto f5fade97e6 chore: drop noisy logs (#8142)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2026-01-21 09:52:20 +01:00

35 lines
788 B
Go

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
}