mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Move to getMachineInfo()
This commit is contained in:
parent
da966f33f4
commit
e56db7d407
@ -21,7 +21,9 @@ package winstats
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
@ -136,10 +138,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 +220,16 @@ func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 {
|
||||
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) {
|
||||
// We use GlobalMemoryStatusEx instead of GetPhysicallyInstalledSystemMemory
|
||||
// on Windows node for the following reasons:
|
||||
|
@ -20,8 +20,6 @@ limitations under the License.
|
||||
package winstats
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
@ -105,24 +103,9 @@ func (c *StatsClient) WinContainerInfos() (map[string]cadvisorapiv2.ContainerInf
|
||||
}
|
||||
|
||||
// WinMachineInfo returns a cadvisorapi.MachineInfo with details about the
|
||||
// node machine. Run the powershell command to get the SystemUUID for Windows node
|
||||
// in here if it isn't provided by cadvisor.
|
||||
// node machine.
|
||||
func (c *StatsClient) WinMachineInfo() (*cadvisorapi.MachineInfo, error) {
|
||||
infos, err := 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
|
||||
return c.client.getMachineInfo()
|
||||
}
|
||||
|
||||
// WinVersionInfo returns a cadvisorapi.VersionInfo with version info of
|
||||
|
@ -121,7 +121,7 @@ func TestWinMachineInfo(t *testing.T) {
|
||||
NumCores: 4,
|
||||
MemoryCapacity: 1.6e+10,
|
||||
MachineID: "somehostname",
|
||||
SystemUUID: machineInfo.SystemUUID,})
|
||||
SystemUUID: machineInfo.SystemUUID})
|
||||
}
|
||||
|
||||
func TestWinVersionInfo(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user