memory and cpus

This commit is contained in:
Jeff Carr 2025-02-15 06:45:14 -06:00
parent 201ec576bc
commit 088a2f6515
2 changed files with 32 additions and 3 deletions

29
apt.go
View File

@ -2,6 +2,9 @@ package zoopb
import (
"fmt"
"runtime"
"golang.org/x/sys/unix"
)
// init the installed package list
@ -25,6 +28,8 @@ func (me *Machine) initPackages() {
me.Packages.Append(new1)
// log.Info("added", new1.Name, "failed")
}
me.getMemory()
}
func (me *Machine) addNew(name string, version string) {
@ -33,3 +38,27 @@ func (me *Machine) addNew(name string, version string) {
new1.Version = version
me.Packages.Append(new1)
}
// simple memory and cpu count
func (me *Machine) getMemory() {
// Get number of CPUs
numCPUs := runtime.NumCPU()
// Get total system memory
var sysInfo unix.Sysinfo_t
err := unix.Sysinfo(&sysInfo)
if err != nil {
fmt.Println("Error getting system info:", err)
return
}
// Convert memory from bytes to GB
totalMemGB := float64(sysInfo.Totalram) * float64(sysInfo.Unit) / (1024 * 1024 * 1024)
m := float64(sysInfo.Totalram) * float64(sysInfo.Unit)
me.Memory = int64(m)
me.Cpus = int64(numCPUs)
// Print results
fmt.Printf("Total Memory: %.2f GB\n", totalMemGB)
fmt.Printf("Number of CPUs: %d\n", numCPUs)
}

View File

@ -71,12 +71,13 @@ func dpkgQuery() (map[string]string, error) {
return installedPackages, scanner.Err()
}
/*
func (me *Machine) UpdatePackages() string {
log.Info("fixme. broken after move to autogenpb")
return ""
}
*/
/*
func (me *Machine) UpdatePackages() string {
// Get the list of installed packages for the detected distro
newP, err := getPackageList(me.Distro)
@ -95,7 +96,7 @@ func (me *Machine) UpdatePackages() string {
newCounter += 1
} else {
found.Version = version
panic("redo this. broken after autogenpb. was never right anyway")
// panic("redo this. broken after autogenpb. was never right anyway")
//if me.Packages.Update(found) {
// changeCounter += 1
//}
@ -111,4 +112,3 @@ func (me *Machine) UpdatePackages() string {
}
return footer
}
*/