pull/1208/head
mmorel-35 4 years ago
parent 04c870cb3d
commit eb5f6203d8

@ -60,7 +60,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
Mhz: float64(c.ProcessorHz / 1000000),
Cores: int32(c.NCpusCfg),
}
result := []InfoStat{info};
result := []InfoStat{info}
return result, nil
}
@ -71,4 +71,3 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
}
return c.NCpusCfg, nil
}

@ -7,8 +7,8 @@ import (
"fmt"
"unsafe"
"github.com/yusufpapurcu/wmi"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/yusufpapurcu/wmi"
"golang.org/x/sys/windows"
)

@ -16,7 +16,7 @@ func init() {
FSType = map[int]string{0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc",
16: "special-fs", 17: "cache-fs", 18: "nfs3", 19: "automount-fs", 20: "pool-fs", 32: "vxfs",
33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs",
39: "ahafs", 40: "sterm-nfs", 41: "asmfs" }
39: "ahafs", 40: "sterm-nfs", 41: "asmfs"}
}
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
@ -28,7 +28,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
for _, fs := range f {
fstyp, exists := FSType[fs.FSType]
if ! exists {
if !exists {
fstyp = "unknown"
}
info := PartitionStat{
@ -36,7 +36,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
Mountpoint: fs.MountPoint,
Fstype: fstyp,
}
ret = append(ret,info)
ret = append(ret, info)
}
return ret, err
@ -56,7 +56,7 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
for _, fs := range f {
if path == fs.MountPoint {
fstyp, exists := FSType[fs.FSType]
if ! exists {
if !exists {
fstyp = "unknown"
}
info := UsageStat{
@ -64,7 +64,7 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
Fstype: fstyp,
Total: uint64(fs.TotalBlocks) * blocksize,
Free: uint64(fs.FreeBlocks) * blocksize,
Used: uint64(fs.TotalBlocks - fs.FreeBlocks) * blocksize,
Used: uint64(fs.TotalBlocks-fs.FreeBlocks) * blocksize,
InodesTotal: uint64(fs.TotalInodes),
InodesFree: uint64(fs.FreeInodes),
InodesUsed: uint64(fs.TotalInodes - fs.FreeInodes),

@ -27,14 +27,14 @@ var (
// A blacklist of read-only virtual filesystems. Writable filesystems are of
// operational concern and must not be included in this list.
fsTypeBlacklist = map[string]struct{}{
"ctfs": struct{}{},
"dev": struct{}{},
"fd": struct{}{},
"lofs": struct{}{},
"lxproc": struct{}{},
"mntfs": struct{}{},
"objfs": struct{}{},
"proc": struct{}{},
"ctfs": {},
"dev": {},
"fd": {},
"lofs": {},
"lxproc": {},
"mntfs": {},
"objfs": {},
"proc": {},
}
)

@ -13,9 +13,9 @@ import (
"time"
"unsafe"
"github.com/yusufpapurcu/wmi"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v3/process"
"github.com/yusufpapurcu/wmi"
"golang.org/x/sys/windows"
)

@ -68,4 +68,3 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) {
}
return &ret, nil
}

@ -41,13 +41,13 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
return nil, err
}
pagesize := uint64(4096)
swapUsed := uint64(m.PgSpTotal - m.PgSpFree - m.PgSpRsvd) * pagesize
swapUsed := uint64(m.PgSpTotal-m.PgSpFree-m.PgSpRsvd) * pagesize
swapTotal := uint64(m.PgSpTotal) * pagesize
ret := SwapMemoryStat{
Total: swapTotal,
Free: uint64(m.PgSpFree) * pagesize,
Used: swapUsed,
UsedPercent: float64(100 * swapUsed) / float64(swapTotal),
UsedPercent: float64(100*swapUsed) / float64(swapTotal),
Sin: uint64(m.PgSpIn),
Sout: uint64(m.PgSpOut),
PgIn: uint64(m.PageIn),

@ -21,10 +21,10 @@ func TestIOCountersByFileParsing(t *testing.T) {
assert.Nil(t, err, "Temporary file creation failed: ", err)
cases := [4][2]string{
[2]string{"eth0: ", "eth1: "},
[2]string{"eth0:0: ", "eth1:0: "},
[2]string{"eth0:", "eth1:"},
[2]string{"eth0:0:", "eth1:0:"},
{"eth0: ", "eth1: "},
{"eth0:0: ", "eth1:0: "},
{"eth0:", "eth1:"},
{"eth0:0:", "eth1:0:"},
}
for _, testCase := range cases {
err = tmpfile.Truncate(0)

@ -333,7 +333,6 @@ func ConntrackStatsWithContext(ctx context.Context, percpu bool) ([]ConntrackSta
return nil, common.ErrNotImplementedError
}
// NetProtoCounters returns network statistics for the entire system
// If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned.

@ -946,7 +946,6 @@ func getProcessCPUTimes(pid int32) (SYSTEM_TIMES, error) {
return times, err
}
func getUserProcessParams32(handle windows.Handle) (rtlUserProcessParameters32, error) {
pebAddress, err := queryPebAddress(syscall.Handle(handle), true)
if err != nil {
@ -1068,14 +1067,14 @@ func getProcessEnvironmentVariables(pid int32, ctx context.Context) ([]string, e
is32BitProcess: procIs32Bits,
offset: processParameterBlockAddress,
})
envvarScanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error){
envvarScanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {
if atEOF && len(data) == 0 {
return 0, nil, nil
}
// Check for UTF-16 zero character
for i := 0; i < len(data) - 1; i+=2 {
for i := 0; i < len(data)-1; i += 2 {
if data[i] == 0 && data[i+1] == 0 {
return i+2, data[0:i], nil
return i + 2, data[0:i], nil
}
}
if atEOF {

Loading…
Cancel
Save