pull/1417/head
shirou 2 years ago
parent 6a5e40a517
commit 852f455217

@ -6,8 +6,8 @@ package cpu
import (
"context"
"regexp"
"strings"
"strconv"
"strings"
"github.com/shirou/gopsutil/v3/internal/common"
)
@ -28,19 +28,19 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
}
ret := TimesStat{CPU: "cpu-total"}
h := whiteSpaces.Split(lines[len(lines)-3], -1) // headers
v := whiteSpaces.Split(lines[len(lines)-2], -1) // values
h := whiteSpaces.Split(lines[len(lines)-3], -1) // headers
v := whiteSpaces.Split(lines[len(lines)-2], -1) // values
for i, header := range h {
if t, err := strconv.ParseFloat(v[i], 64); err == nil {
switch header {
case `%usr`:
ret.User = t
case `%sys`:
ret.System = t
case `%wio`:
ret.Iowait = t
case `%idle`:
ret.Idle = t
case `%usr`:
ret.User = t
case `%sys`:
ret.System = t
case `%wio`:
ret.Iowait = t
case `%idle`:
ret.Idle = t
}
}
}

@ -8,8 +8,8 @@ import (
"regexp"
"strings"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
)
var whiteSpaces = regexp.MustCompile(`\s+`)
@ -17,11 +17,11 @@ var startBlank = regexp.MustCompile(`^\s+`)
var ignoreFSType = map[string]bool{"procfs": true}
var 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",
}
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",
}
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
var ret []PartitionStat
@ -42,7 +42,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
start := 0
finished := false
for pos, ch := range lines[1] {
if ch == ' ' && ! finished {
if ch == ' ' && !finished {
name := strings.TrimSpace(lines[0][start:pos])
colidx[name] = idx
finished = true

@ -12,9 +12,8 @@ import (
"strconv"
"strings"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
)
// PartitionsWithContext returns disk partition.

@ -21,6 +21,7 @@ package common
// high-performance serialization, especially for large data structures,
// should look at more advanced solutions such as the encoding/gob
// package or protocol buffers.
import (
"errors"
"io"

@ -6,6 +6,7 @@ package common
// - linux (amd64, arm)
// - freebsd (amd64)
// - windows (amd64)
import (
"bufio"
"bytes"

@ -218,9 +218,12 @@ func WMIQueryWithContext(ctx context.Context, query string, dst interface{}, con
}
// Convert paths using native DOS format like:
// "\Device\HarddiskVolume1\Windows\systemew\file.txt"
//
// "\Device\HarddiskVolume1\Windows\systemew\file.txt"
//
// into:
// "C:\Windows\systemew\file.txt"
//
// "C:\Windows\systemew\file.txt"
func ConvertDOSPath(p string) string {
rawDrive := strings.Join(strings.Split(p, `\`)[:3], `\`)

@ -53,13 +53,13 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) {
for _, line := range strings.Split(string(out), "\n") {
ret.ProcsTotal++
switch line {
case "R":
case "A":
ret.ProcsRunning++
case "T":
ret.ProcsBlocked++
default:
continue
case "R":
case "A":
ret.ProcsRunning++
case "T":
ret.ProcsBlocked++
default:
continue
}
}
return ret, nil

@ -71,7 +71,7 @@ func callSVMon(ctx context.Context) (*VirtualMemoryStat, *SwapMemoryStat, error)
swap.Total = t * pagesize
}
if t, err := strconv.ParseUint(p[3], 10, 64); err == nil {
swap.Free = swap.Total - t * pagesize
swap.Free = swap.Total - t*pagesize
}
}
break

@ -8,9 +8,8 @@ import (
"errors"
"unsafe"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
)
func VirtualMemory() (*VirtualMemoryStat, error) {

@ -9,6 +9,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
)

@ -18,14 +18,14 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
iocounters := make([]IOCountersStat, 0, len(ifs))
for _, netif := range ifs {
n := IOCountersStat{
Name: netif.Name,
BytesSent: uint64(netif.OBytes),
BytesRecv: uint64(netif.IBytes),
Name: netif.Name,
BytesSent: uint64(netif.OBytes),
BytesRecv: uint64(netif.IBytes),
PacketsSent: uint64(netif.OPackets),
PacketsRecv: uint64(netif.IPackets),
Errin: uint64(netif.OErrors),
Errout: uint64(netif.IErrors),
Dropout: uint64(netif.XmitDrops),
Errin: uint64(netif.OErrors),
Errout: uint64(netif.IErrors),
Dropout: uint64(netif.XmitDrops),
}
iocounters = append(iocounters, n)
}

@ -211,7 +211,8 @@ func IOCountersByFileWithContext(ctx context.Context, pernic bool, filename stri
// Return a list of network connections
// Available kind:
// reference to netConnectionKindMap
//
// reference to netConnectionKindMap
func Connections(kind string) ([]ConnectionStat, error) {
return ConnectionsWithContext(context.Background(), kind)
}

@ -8,9 +8,8 @@ import (
"syscall"
"unsafe"
"golang.org/x/sys/windows"
"github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/windows"
)
type PROCESS_MEMORY_COUNTERS struct {

Loading…
Cancel
Save