MCPcopy
hub / github.com/mudler/LocalAI / GetSystemRAMInfo

Function GetSystemRAMInfo

pkg/xsysinfo/memory.go:53–77  ·  view source on GitHub ↗

GetSystemRAMInfo returns real-time system RAM usage

()

Source from the content-addressed store, hash-verified

51
52// GetSystemRAMInfo returns real-time system RAM usage
53func GetSystemRAMInfo() (*SystemRAMInfo, error) {
54 total := systemTotalMemory()
55 available := memory.AvailableMemory()
56
57 // AvailableMemory (MemAvailable) is virtualized by lxcfs, so in edge
58 // cases it can exceed our corrected total; clamp to avoid an unsigned
59 // underflow when computing Used.
60 if available > total {
61 available = total
62 }
63
64 used := total - available
65
66 usagePercent := 0.0
67 if total > 0 {
68 usagePercent = float64(used) / float64(total) * 100
69 }
70 return &SystemRAMInfo{
71 Total: total,
72 Used: used,
73 Free: available,
74 Available: available,
75 UsagePercent: usagePercent,
76 }, nil
77}

Callers 7

RegisterUIAPIRoutesFunction · 0.92
registrationBodyMethod · 0.92
heartbeatBodyMethod · 0.92
getNVIDIAGPUMemoryFunction · 0.85
GetResourceInfoFunction · 0.85
getAppleGPUMemoryFunction · 0.85

Calls 1

systemTotalMemoryFunction · 0.85

Tested by

no test coverage detected