GetSystemRAMInfo returns real-time system RAM usage
()
| 51 | |
| 52 | // GetSystemRAMInfo returns real-time system RAM usage |
| 53 | func 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 | } |
no test coverage detected