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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// init the installed package list
|
// init the installed package list
|
||||||
|
@ -25,6 +28,8 @@ func (me *Machine) initPackages() {
|
||||||
me.Packages.Append(new1)
|
me.Packages.Append(new1)
|
||||||
// log.Info("added", new1.Name, "failed")
|
// log.Info("added", new1.Name, "failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
me.getMemory()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me *Machine) addNew(name string, version string) {
|
func (me *Machine) addNew(name string, version string) {
|
||||||
|
@ -33,3 +38,27 @@ func (me *Machine) addNew(name string, version string) {
|
||||||
new1.Version = version
|
new1.Version = version
|
||||||
me.Packages.Append(new1)
|
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()
|
return installedPackages, scanner.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func (me *Machine) UpdatePackages() string {
|
func (me *Machine) UpdatePackages() string {
|
||||||
log.Info("fixme. broken after move to autogenpb")
|
log.Info("fixme. broken after move to autogenpb")
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
func (me *Machine) UpdatePackages() string {
|
func (me *Machine) UpdatePackages() string {
|
||||||
// Get the list of installed packages for the detected distro
|
// Get the list of installed packages for the detected distro
|
||||||
newP, err := getPackageList(me.Distro)
|
newP, err := getPackageList(me.Distro)
|
||||||
|
@ -95,7 +96,7 @@ func (me *Machine) UpdatePackages() string {
|
||||||
newCounter += 1
|
newCounter += 1
|
||||||
} else {
|
} else {
|
||||||
found.Version = version
|
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) {
|
//if me.Packages.Update(found) {
|
||||||
// changeCounter += 1
|
// changeCounter += 1
|
||||||
//}
|
//}
|
||||||
|
@ -111,4 +112,3 @@ func (me *Machine) UpdatePackages() string {
|
||||||
}
|
}
|
||||||
return footer
|
return footer
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
Loading…
Reference in New Issue