Move to getMachineInfo()

This commit is contained in:
Angela Li 2019-07-23 13:25:12 -07:00
parent da966f33f4
commit e56db7d407
3 changed files with 21 additions and 20 deletions

View File

@ -21,7 +21,9 @@ package winstats
import ( import (
"errors" "errors"
"os" "os"
"os/exec"
"runtime" "runtime"
"strings"
"sync" "sync"
"time" "time"
"unsafe" "unsafe"
@ -136,10 +138,16 @@ func (p *perfCounterNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo,
return nil, err return nil, err
} }
systemUUID, err := getSystemUUID()
if err != nil {
return nil, err
}
return &cadvisorapi.MachineInfo{ return &cadvisorapi.MachineInfo{
NumCores: runtime.NumCPU(), NumCores: runtime.NumCPU(),
MemoryCapacity: p.nodeInfo.memoryPhysicalCapacityBytes, MemoryCapacity: p.nodeInfo.memoryPhysicalCapacityBytes,
MachineID: hostname, MachineID: hostname,
SystemUUID: systemUUID,
}, nil }, nil
} }
@ -212,6 +220,16 @@ func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 {
return cpuUsageNanoCores return cpuUsageNanoCores
} }
func getSystemUUID() (string, error) {
cmd := exec.Command("powershell.exe", "-Command", "(Get-CimInstance -Class Win32_ComputerSystemProduct).UUID")
out, err := cmd.CombinedOutput()
if err != nil {
return "", err
}
systemUUID := strings.TrimRight(string(out), "\r\n")
return systemUUID, nil
}
func getPhysicallyInstalledSystemMemoryBytes() (uint64, error) { func getPhysicallyInstalledSystemMemoryBytes() (uint64, error) {
// We use GlobalMemoryStatusEx instead of GetPhysicallyInstalledSystemMemory // We use GlobalMemoryStatusEx instead of GetPhysicallyInstalledSystemMemory
// on Windows node for the following reasons: // on Windows node for the following reasons:

View File

@ -20,8 +20,6 @@ limitations under the License.
package winstats package winstats
import ( import (
"os/exec"
"strings"
"syscall" "syscall"
"time" "time"
"unsafe" "unsafe"
@ -105,24 +103,9 @@ func (c *StatsClient) WinContainerInfos() (map[string]cadvisorapiv2.ContainerInf
} }
// WinMachineInfo returns a cadvisorapi.MachineInfo with details about the // WinMachineInfo returns a cadvisorapi.MachineInfo with details about the
// node machine. Run the powershell command to get the SystemUUID for Windows node // node machine.
// in here if it isn't provided by cadvisor.
func (c *StatsClient) WinMachineInfo() (*cadvisorapi.MachineInfo, error) { func (c *StatsClient) WinMachineInfo() (*cadvisorapi.MachineInfo, error) {
infos, err := c.client.getMachineInfo() return c.client.getMachineInfo()
if err != nil {
return nil, err
}
if infos.SystemUUID == "" {
cmd := exec.Command("powershell.exe", "-Command", "(Get-CimInstance -Class Win32_ComputerSystemProduct).UUID")
out, err := cmd.CombinedOutput()
if err != nil {
return infos, err
}
infos.SystemUUID = strings.TrimRight(string(out), "\r\n")
}
return infos, nil
} }
// WinVersionInfo returns a cadvisorapi.VersionInfo with version info of // WinVersionInfo returns a cadvisorapi.VersionInfo with version info of

View File

@ -121,7 +121,7 @@ func TestWinMachineInfo(t *testing.T) {
NumCores: 4, NumCores: 4,
MemoryCapacity: 1.6e+10, MemoryCapacity: 1.6e+10,
MachineID: "somehostname", MachineID: "somehostname",
SystemUUID: machineInfo.SystemUUID,}) SystemUUID: machineInfo.SystemUUID})
} }
func TestWinVersionInfo(t *testing.T) { func TestWinVersionInfo(t *testing.T) {