mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
Update host.Info() to return the number of processes on all platforms.
Fixes: #227
This commit is contained in:
parent
d2ca7e8d2c
commit
69f7f8eaeb
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user