mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
24 lines
512 B
Go
24 lines
512 B
Go
package utils
|
|
|
|
import (
|
|
"log/slog"
|
|
"oneuptime-infrastructure-agent/model"
|
|
|
|
"github.com/shirou/gopsutil/v3/mem"
|
|
)
|
|
|
|
func GetMemoryMetrics() *model.MemoryMetrics {
|
|
memoryInfo, err := mem.VirtualMemory()
|
|
if err != nil {
|
|
slog.Error("Error while fetching memory metrics: ", err)
|
|
return nil
|
|
}
|
|
return &model.MemoryMetrics{
|
|
Total: memoryInfo.Total,
|
|
Free: memoryInfo.Free,
|
|
Used: memoryInfo.Used,
|
|
PercentUsed: memoryInfo.UsedPercent,
|
|
PercentFree: 100 - memoryInfo.UsedPercent,
|
|
}
|
|
}
|