Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions pkg/xsysinfo/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package xsysinfo
import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
"strconv"
"strings"
"sync"

sigar "github.com/cloudfoundry/gosigar"
"github.com/jaypipes/ghw"
"github.com/jaypipes/ghw/pkg/gpu"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -53,15 +51,6 @@ type GPUAggregateInfo struct {
GPUCount int `json:"gpu_count"`
}

// 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"`
}

// AggregateMemoryInfo contains aggregate memory information (unified for GPU/RAM)
type AggregateMemoryInfo struct {
TotalMemory uint64 `json:"total_memory"`
Expand Down Expand Up @@ -144,21 +133,6 @@ func isUnifiedMemoryDevice(gpuName string) bool {
return false
}

// getSystemRAM returns system RAM information using ghw
func getSystemRAM() (total, used, free uint64, err error) {
mem := sigar.Mem{}
//swap := sigar.Swap{}

mem.Get() //nolint:errcheck
//swap.Get() //nolint:errcheck

total = mem.Total
free = mem.ActualFree
used = mem.ActualUsed

return total, used, free, nil
}

// GetGPUMemoryUsage returns real-time GPU memory usage for all detected GPUs.
// It tries multiple vendor-specific tools in order: NVIDIA, AMD, Intel, Vulkan.
// Returns an empty slice if no GPU monitoring tools are available.
Expand Down Expand Up @@ -558,29 +532,6 @@ func getIntelGPUTop() []GPUMemoryInfo {
return nil
}

// GetSystemRAMInfo returns real-time system RAM usage
func GetSystemRAMInfo() (*SystemRAMInfo, error) {
total, used, free, err := getSystemRAM()
if err != nil {
return nil, err
}

usagePercent := 0.0
if total > 0 {
usagePercent = float64(used) / float64(total) * 100
}

fmt.Println("total", total, "used", used, "free", free)

return &SystemRAMInfo{
Total: total,
Used: used,
Free: free,
Available: total - used,
UsagePercent: usagePercent,
}, nil
}

// GetResourceInfo returns GPU info if available, otherwise system RAM info
func GetResourceInfo() ResourceInfo {
gpus := GetGPUMemoryUsage()
Expand Down
47 changes: 47 additions & 0 deletions pkg/xsysinfo/memory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package xsysinfo

import (
sigar "github.com/cloudfoundry/gosigar"
"github.com/rs/zerolog/log"
)

// 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, used, free, err := getSystemRAM()
if err != nil {
return nil, err
}

usagePercent := 0.0
if total > 0 {
usagePercent = float64(used) / float64(total) * 100
}
log.Debug().Uint64("total", total).Uint64("used", used).Uint64("free", free).Float64("usage_percent", usagePercent).Msg("System RAM Info")
return &SystemRAMInfo{
Total: total,
Used: used,
Free: free,
Available: total - used,
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
}
Loading