diff --git a/pkg/kubelet/winstats/perfcounter_nodestats.go b/pkg/kubelet/winstats/perfcounter_nodestats.go index dc4ddf6fe24..317c08bf028 100644 --- a/pkg/kubelet/winstats/perfcounter_nodestats.go +++ b/pkg/kubelet/winstats/perfcounter_nodestats.go @@ -20,8 +20,11 @@ package winstats import ( "errors" + "fmt" "os" + "os/exec" "runtime" + "strings" "sync" "time" "unsafe" @@ -136,10 +139,16 @@ func (p *perfCounterNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo, return nil, err } + systemUUID, err := getSystemUUID() + if err != nil { + return nil, err + } + return &cadvisorapi.MachineInfo{ NumCores: runtime.NumCPU(), MemoryCapacity: p.nodeInfo.memoryPhysicalCapacityBytes, MachineID: hostname, + SystemUUID: systemUUID, }, nil } @@ -212,6 +221,18 @@ func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 { return cpuUsageNanoCores } +func getSystemUUID() (string, error) { + result, err := exec.Command("wmic", "csproduct", "get", "UUID").Output() + if err != nil { + return "", err + } + fields := strings.Fields(string(result)) + if len(fields) != 2 { + return "", fmt.Errorf("received unexpected value retrieving vm uuid: %q", string(result)) + } + return fields[1], nil +} + func getPhysicallyInstalledSystemMemoryBytes() (uint64, error) { // We use GlobalMemoryStatusEx instead of GetPhysicallyInstalledSystemMemory // on Windows node for the following reasons: diff --git a/pkg/kubelet/winstats/winstats_test.go b/pkg/kubelet/winstats/winstats_test.go index 45c33132c64..50dc98d68c6 100644 --- a/pkg/kubelet/winstats/winstats_test.go +++ b/pkg/kubelet/winstats/winstats_test.go @@ -56,6 +56,7 @@ func (f fakeWinNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo, erro NumCores: 4, MemoryCapacity: 1.6e+10, MachineID: "somehostname", + SystemUUID: "E6C8AC43-582B-3575-4E1F-6DA170888906", }, nil } @@ -118,7 +119,8 @@ func TestWinMachineInfo(t *testing.T) { assert.Equal(t, machineInfo, &cadvisorapi.MachineInfo{ NumCores: 4, MemoryCapacity: 1.6e+10, - MachineID: "somehostname"}) + MachineID: "somehostname", + SystemUUID: "E6C8AC43-582B-3575-4E1F-6DA170888906"}) } func TestWinVersionInfo(t *testing.T) {