summaryrefslogtreecommitdiff
path: root/hw.go
blob: fd8f182c384b7c188ce0fbac908ccb85373dc9ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package debian

import (
	"fmt"
	"runtime"

	"go.wit.com/lib/protobuf/zoopb"
	"golang.org/x/sys/unix"
)

// init the installed package list
func getMemory(me *zoopb.Machine) {
	// 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)
}