diff options
| author | Jeff Carr <[email protected]> | 2025-02-15 06:45:14 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-02-15 07:28:49 -0600 |
| commit | 088a2f65152a84583519fe89effbd92435e0eb2e (patch) | |
| tree | d15455dd30c7490185c336d72a162580a6cf6cb1 /apt.go | |
| parent | 201ec576bcd66035542cebf15b461b4a5d4efa39 (diff) | |
memory and cpusv0.0.26
Diffstat (limited to 'apt.go')
| -rw-r--r-- | apt.go | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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) +} |
