diff --git a/host/host_darwin.go b/host/host_darwin.go index f4a8c36..00781cd 100644 --- a/host/host_darwin.go +++ b/host/host_darwin.go @@ -15,6 +15,7 @@ import ( "unsafe" "github.com/shirou/gopsutil/internal/common" + "github.com/shirou/gopsutil/process" ) // from utmpx.h @@ -37,6 +38,7 @@ func Info() (*InfoStat, error) { ret.PlatformFamily = family ret.PlatformVersion = version } + system, role, err := Virtualization() if err == nil { ret.VirtualizationSystem = system @@ -49,6 +51,11 @@ func Info() (*InfoStat, error) { ret.Uptime = uptime(boot) } + procs, err := process.Pids() + if err == nil { + ret.Procs = uint64(len(procs)) + } + return ret, nil } diff --git a/host/host_freebsd.go b/host/host_freebsd.go index aeb1b45..e4bfbc9 100644 --- a/host/host_freebsd.go +++ b/host/host_freebsd.go @@ -15,6 +15,7 @@ import ( "unsafe" "github.com/shirou/gopsutil/internal/common" + "github.com/shirou/gopsutil/process" ) const ( @@ -40,6 +41,7 @@ func Info() (*InfoStat, error) { ret.PlatformFamily = family ret.PlatformVersion = version } + system, role, err := Virtualization() if err == nil { ret.VirtualizationSystem = system @@ -52,6 +54,11 @@ func Info() (*InfoStat, error) { ret.Uptime = uptime(boot) } + procs, err := process.Pids() + if err == nil { + ret.Procs = uint64(len(procs)) + } + return ret, nil } diff --git a/host/host_linux.go b/host/host_linux.go index 14d0935..3e69983 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -16,6 +16,7 @@ import ( "time" "github.com/shirou/gopsutil/internal/common" + "github.com/shirou/gopsutil/process" ) type LSB struct { @@ -44,17 +45,24 @@ func Info() (*InfoStat, error) { ret.PlatformFamily = family ret.PlatformVersion = version } + system, role, err := Virtualization() if err == nil { ret.VirtualizationSystem = system ret.VirtualizationRole = role } + boot, err := BootTime() if err == nil { ret.BootTime = boot ret.Uptime = uptime(boot) } + procs, err := process.Pids() + if err == nil { + ret.Procs = uint64(len(procs)) + } + return ret, nil } diff --git a/host/host_test.go b/host/host_test.go index 2bf395c..05975e1 100644 --- a/host/host_test.go +++ b/host/host_test.go @@ -14,6 +14,9 @@ func TestHostInfo(t *testing.T) { if v == empty { t.Errorf("Could not get hostinfo %v", v) } + if v.Procs == 0 { + t.Errorf("Could not determine the number of host processes") + } } func TestBoot_time(t *testing.T) { diff --git a/host/host_windows.go b/host/host_windows.go index 29f900c..56909f7 100644 --- a/host/host_windows.go +++ b/host/host_windows.go @@ -54,12 +54,10 @@ func Info() (*InfoStat, error) { } procs, err := process.Pids() - if err != nil { - return ret, err + if err == nil { + ret.Procs = uint64(len(procs)) } - ret.Procs = uint64(len(procs)) - return ret, nil }