memory and cpus
This commit is contained in:
parent
201ec576bc
commit
088a2f6515
29
apt.go
29
apt.go
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue