mirror of
https://github.com/mudler/LocalAI.git
synced 2026-02-16 06:59:36 -06:00
chore(memory detection): do not use go-sigar as requires CGO on darwin (#7618)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
committed by
GitHub
parent
f251bdee64
commit
3ca90876f1
4
go.mod
4
go.mod
@@ -10,7 +10,6 @@ require (
|
||||
github.com/Masterminds/sprig/v3 v3.3.0
|
||||
github.com/alecthomas/kong v1.13.0
|
||||
github.com/charmbracelet/glamour v0.10.0
|
||||
github.com/cloudfoundry/gosigar v1.3.112
|
||||
github.com/containerd/containerd v1.7.29
|
||||
github.com/ebitengine/purego v0.9.1
|
||||
github.com/fsnotify/fsnotify v1.9.0
|
||||
@@ -66,6 +65,7 @@ require (
|
||||
require (
|
||||
github.com/ghodss/yaml v1.0.0 // indirect
|
||||
github.com/labstack/gommon v0.4.2 // indirect
|
||||
github.com/mudler/memory v0.0.0-20251216220809-d1256471a6c2 // indirect
|
||||
github.com/swaggo/files/v2 v2.0.2 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||
)
|
||||
@@ -273,7 +273,7 @@ require (
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.1.1
|
||||
github.com/opentracing/opentracing-go v1.2.0 // indirect
|
||||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
|
||||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
|
||||
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.2 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
|
||||
4
go.sum
4
go.sum
@@ -83,8 +83,6 @@ github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNE
|
||||
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
|
||||
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cloudfoundry/gosigar v1.3.112 h1:cGGZ2sj1GKyiwSxzouIR7ATNbgAkC4zqwWDxYQ2ObPc=
|
||||
github.com/cloudfoundry/gosigar v1.3.112/go.mod h1:Ldc+tVw3dfqPwasZ9om1LT2aRwpjC1eFfbWKfv2WbDI=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
|
||||
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
|
||||
@@ -516,6 +514,8 @@ github.com/mudler/go-piper v0.0.0-20241023091659-2494246fd9fc h1:RxwneJl1VgvikiX
|
||||
github.com/mudler/go-piper v0.0.0-20241023091659-2494246fd9fc/go.mod h1:O7SwdSWMilAWhBZMK9N9Y/oBDyMMzshE3ju8Xkexwig=
|
||||
github.com/mudler/go-processmanager v0.0.0-20240820160718-8b802d3ecf82 h1:FVT07EI8njvsD4tC2Hw8Xhactp5AWhsQWD4oTeQuSAU=
|
||||
github.com/mudler/go-processmanager v0.0.0-20240820160718-8b802d3ecf82/go.mod h1:Urp7LG5jylKoDq0663qeBh0pINGcRl35nXdKx82PSoU=
|
||||
github.com/mudler/memory v0.0.0-20251216220809-d1256471a6c2 h1:+WHsL/j6EWOMUiMVIOJNKOwSKiQt/qDPc9fePCf87fA=
|
||||
github.com/mudler/memory v0.0.0-20251216220809-d1256471a6c2/go.mod h1:EA8Ashhd56o32qN7ouPKFSRUs/Z+LrRCF4v6R2Oarm8=
|
||||
github.com/mudler/water v0.0.0-20250808092830-dd90dcf09025 h1:WFLP5FHInarYGXi6B/Ze204x7Xy6q/I4nCZnWEyPHK0=
|
||||
github.com/mudler/water v0.0.0-20250808092830-dd90dcf09025/go.mod h1:QuIFdRstyGJt+MTTkWY+mtD7U6xwjOR6SwKUjmLZtR4=
|
||||
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
|
||||
|
||||
@@ -244,7 +244,7 @@ func getNVIDIAGPUMemory() []GPUMemoryInfo {
|
||||
|
||||
if isNA && isUnifiedMemoryDevice(name) {
|
||||
// Unified memory device - fall back to system RAM
|
||||
sysTotal, sysUsed, sysFree, err := getSystemRAM()
|
||||
sysInfo, err := GetSystemRAMInfo()
|
||||
if err != nil {
|
||||
log.Debug().Err(err).Str("device", name).Msg("failed to get system RAM for unified memory device")
|
||||
// Still add the GPU but with zero memory info
|
||||
@@ -260,9 +260,9 @@ func getNVIDIAGPUMemory() []GPUMemoryInfo {
|
||||
continue
|
||||
}
|
||||
|
||||
totalBytes = sysTotal
|
||||
usedBytes = sysUsed
|
||||
freeBytes = sysFree
|
||||
totalBytes = sysInfo.Total
|
||||
usedBytes = sysInfo.Used
|
||||
freeBytes = sysInfo.Free
|
||||
if totalBytes > 0 {
|
||||
usagePercent = float64(usedBytes) / float64(totalBytes) * 100
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package xsysinfo
|
||||
|
||||
import (
|
||||
sigar "github.com/cloudfoundry/gosigar"
|
||||
"github.com/mudler/memory"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
@@ -16,10 +16,10 @@ type SystemRAMInfo struct {
|
||||
|
||||
// GetSystemRAMInfo returns real-time system RAM usage
|
||||
func GetSystemRAMInfo() (*SystemRAMInfo, error) {
|
||||
total, used, free, err := getSystemRAM()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
total := memory.TotalMemory()
|
||||
free := memory.AvailableMemory()
|
||||
|
||||
used := total - free
|
||||
|
||||
usagePercent := 0.0
|
||||
if total > 0 {
|
||||
@@ -34,14 +34,3 @@ func GetSystemRAMInfo() (*SystemRAMInfo, error) {
|
||||
UsagePercent: usagePercent,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// getSystemRAM returns system RAM information using ghw
|
||||
func getSystemRAM() (total, used, free uint64, err error) {
|
||||
mem := sigar.Mem{}
|
||||
|
||||
if err := mem.GetIgnoringCGroups(); err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
|
||||
return mem.Total, mem.ActualUsed, mem.ActualFree, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user