zoopb/apt.go

65 lines
1.4 KiB
Go

package zoopb
import (
"fmt"
"runtime"
"golang.org/x/sys/unix"
)
// init the installed package list
func (me *Machine) initPackages() {
// Get the list of installed packages for the detected distro
newP, err := getPackageList(me.Distro)
if err != nil {
fmt.Println("Error:", err)
return
}
if me.Packages == nil {
me.Packages = new(Packages)
}
// Print the installed packages and their versions
for pkg, version := range newP {
new1 := new(Package)
new1.Name = pkg
new1.Version = version
me.Packages.Append(new1)
// log.Info("added", new1.Name, "failed")
}
me.getMemory()
}
func (me *Machine) addNew(name string, version string) {
new1 := new(Package)
new1.Name = name
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
m := float64(sysInfo.Totalram) * float64(sysInfo.Unit)
me.Memory = int64(m)
me.Cpus = int64(numCPUs)
// totalMemGB := float64(sysInfo.Totalram) * float64(sysInfo.Unit) / (1024 * 1024 * 1024)
// Print results
// fmt.Printf("Total Memory: %.2f GB\n", totalMemGB)
// fmt.Printf("Number of CPUs: %d\n", numCPUs)
}