github.com/ehazlett/containerd@v0.2.5/supervisor/machine.go (about)

     1  // +build !solaris
     2  
     3  package supervisor
     4  
     5  import "github.com/cloudfoundry/gosigar"
     6  
     7  // Machine holds the current machine cpu count and ram size
     8  type Machine struct {
     9  	Cpus   int
    10  	Memory int64
    11  }
    12  
    13  // CollectMachineInformation returns information regarding the current
    14  // machine (e.g. CPU count, RAM amount)
    15  func CollectMachineInformation() (Machine, error) {
    16  	m := Machine{}
    17  	cpu := sigar.CpuList{}
    18  	if err := cpu.Get(); err != nil {
    19  		return m, err
    20  	}
    21  	m.Cpus = len(cpu.List)
    22  	mem := sigar.Mem{}
    23  	if err := mem.Get(); err != nil {
    24  		return m, err
    25  	}
    26  	m.Memory = int64(mem.Total / 1024 / 1024)
    27  	return m, nil
    28  }