[host] Fix #737 add KernelArch field in InfoStat struct returning 'uname -m' result

pull/745/head
Lomanic 6 years ago
parent 98c779765f
commit 4bf185067d

@ -20,6 +20,7 @@ type InfoStat struct {
PlatformFamily string `json:"platformFamily"` // ex: debian, rhel
PlatformVersion string `json:"platformVersion"` // version of the complete OS
KernelVersion string `json:"kernelVersion"` // version of the OS kernel (if available)
KernelArch string `json:"kernelArch"` // native cpu architecture queried at runtime, as returned by `uname -m` or empty string in case of error
VirtualizationSystem string `json:"virtualizationSystem"`
VirtualizationRole string `json:"virtualizationRole"` // guest or host
HostID string `json:"hostid"` // ex: uuid

@ -43,6 +43,11 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
ret.KernelVersion = kernelVersion
}
kernelArch, err := kernelArch()
if err == nil {
ret.KernelArch = kernelArch
}
platform, family, pver, err := PlatformInformation()
if err == nil {
ret.Platform = platform

@ -50,6 +50,11 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
ret.KernelVersion = version
}
kernelArch, err := kernelArch()
if err == nil {
ret.KernelArch = kernelArch
}
system, role, err := Virtualization()
if err == nil {
ret.VirtualizationSystem = system

@ -55,6 +55,11 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
ret.KernelVersion = kernelVersion
}
kernelArch, err := kernelArch()
if err == nil {
ret.KernelArch = kernelArch
}
system, role, err := Virtualization()
if err == nil {
ret.VirtualizationSystem = system

@ -40,6 +40,11 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
ret.Hostname = hostname
}
kernelArch, err := kernelArch()
if err == nil {
ret.KernelArch = kernelArch
}
platform, family, version, err := PlatformInformation()
if err == nil {
ret.Platform = platform

@ -0,0 +1,13 @@
// +build linux freebsd openbsd darwin solaris
package host
import (
"golang.org/x/sys/unix"
)
func kernelArch() (string, error) {
var utsname unix.Utsname
err := unix.Uname(&utsname)
return string(utsname.Machine[:]), err
}

@ -54,6 +54,11 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
result.PlatformVersion = fields[2]
}
kernelArch, err := kernelArch()
if err == nil {
result.KernelArch = kernelArch
}
// Find distribution name from /etc/release
fh, err := os.Open("/etc/release")
if err != nil {

@ -24,6 +24,7 @@ var (
procGetSystemTimeAsFileTime = common.Modkernel32.NewProc("GetSystemTimeAsFileTime")
procGetTickCount32 = common.Modkernel32.NewProc("GetTickCount")
procGetTickCount64 = common.Modkernel32.NewProc("GetTickCount64")
procGetNativeSystemInfo = common.Modkernel32.NewProc("GetNativeSystemInfo")
procRtlGetVersion = common.ModNt.NewProc("RtlGetVersion")
)
@ -42,6 +43,20 @@ type osVersionInfoExW struct {
wReserved uint8
}
type systemInfo struct {
wProcessorArchitecture uint16
wReserved uint16
dwPageSize uint32
lpMinimumApplicationAddress uintptr
lpMaximumApplicationAddress uintptr
dwActiveProcessorMask uintptr
dwNumberOfProcessors uint32
dwProcessorType uint32
dwAllocationGranularity uint32
wProcessorLevel uint16
wProcessorRevision uint16
}
type msAcpi_ThermalZoneTemperature struct {
Active bool
CriticalTripPoint uint32
@ -77,6 +92,13 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
}
{
kernelArch, err := kernelArch()
if err == nil {
ret.KernelArch = kernelArch
}
}
{
boot, err := BootTimeWithContext(ctx)
if err == nil {
ret.BootTime = boot
@ -293,3 +315,35 @@ func KernelVersionWithContext(ctx context.Context) (string, error) {
_, _, version, err := PlatformInformation()
return version, err
}
func kernelArch() (string, error) {
var systemInfo systemInfo
procGetNativeSystemInfo.Call(uintptr(unsafe.Pointer(&systemInfo)))
const (
PROCESSOR_ARCHITECTURE_INTEL = 0
PROCESSOR_ARCHITECTURE_ARM = 5
PROCESSOR_ARCHITECTURE_ARM64 = 12
PROCESSOR_ARCHITECTURE_IA64 = 6
PROCESSOR_ARCHITECTURE_AMD64 = 9
)
switch systemInfo.wProcessorArchitecture {
case PROCESSOR_ARCHITECTURE_INTEL:
if systemInfo.wProcessorLevel < 3 {
return "i386", nil
}
if systemInfo.wProcessorLevel > 6 {
return "i686", nil
}
return fmt.Sprintf("i%d86", systemInfo.wProcessorLevel), nil
case PROCESSOR_ARCHITECTURE_ARM:
return "arm", nil
case PROCESSOR_ARCHITECTURE_ARM64:
return "aarch64", nil
case PROCESSOR_ARCHITECTURE_IA64:
return "ia64", nil
case PROCESSOR_ARCHITECTURE_AMD64:
return "x86_64", nil
}
return "", nil
}

Loading…
Cancel
Save