fix(deps): update module github.com/shirou/gopsutil/v4 to v4.25.6

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2025-07-01 07:13:01 +00:00
committed by GitHub
parent 87d88c3b09
commit 10a5f9715b
20 changed files with 113 additions and 65 deletions

View File

@ -135,7 +135,7 @@ func finishCPUInfo(ctx context.Context, c *InfoStat) {
var err error
var value float64
if len(c.CoreID) == 0 {
if c.CoreID == "" {
lines, err = common.ReadLines(sysCPUPath(ctx, c.CPU, "topology/core_id"))
if err == nil {
c.CoreID = lines[0]

View File

@ -140,8 +140,8 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
}
result := make([]InfoStat, 0, len(flags))
for _, proc := range procs {
procWithFlags := proc
for i := range procs {
procWithFlags := procs[i]
procWithFlags.Flags = flags
result = append(result, procWithFlags)
}
@ -149,7 +149,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
return result, nil
}
var flagsMatch = regexp.MustCompile(`[\w\.]+`)
var flagsMatch = regexp.MustCompile(`[\w.]+`)
func parseISAInfo(cmdOutput string) ([]string, error) {
words := flagsMatch.FindAllString(cmdOutput, -1)

View File

@ -115,7 +115,7 @@ func ReadLines(filename string) ([]string, error) {
}
// ReadLine reads a file and returns the first occurrence of a line that is prefixed with prefix.
func ReadLine(filename string, prefix string) (string, error) {
func ReadLine(filename, prefix string) (string, error) {
f, err := os.Open(filename)
if err != nil {
return "", err
@ -156,7 +156,7 @@ func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
for i := uint(0); i < uint(n)+offset || n < 0; i++ {
line, err := r.ReadString('\n')
if err != nil {
if err == io.EOF && len(line) > 0 {
if err == io.EOF && line != "" {
ret = append(ret, strings.Trim(line, "\n"))
}
break
@ -349,7 +349,7 @@ func PathExistsWithContents(filename string) bool {
// GetEnvWithContext retrieves the environment variable key. If it does not exist it returns the default.
// The context may optionally contain a map superseding os.EnvKey.
func GetEnvWithContext(ctx context.Context, key string, dfault string, combineWith ...string) string {
func GetEnvWithContext(ctx context.Context, key, dfault string, combineWith ...string) string {
var value string
if env, ok := ctx.Value(common.EnvKey).(common.EnvMap); ok {
value = env[common.EnvKeyType(key)]
@ -365,7 +365,7 @@ func GetEnvWithContext(ctx context.Context, key string, dfault string, combineWi
}
// GetEnv retrieves the environment variable key. If it does not exist it returns the default.
func GetEnv(key string, dfault string, combineWith ...string) string {
func GetEnv(key, dfault string, combineWith ...string) string {
value := os.Getenv(key)
if value == "" {
value = dfault

View File

@ -317,11 +317,11 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
return system, role, nil
}
func GetOSRelease() (platform string, version string, err error) {
func GetOSRelease() (platform, version string, err error) {
return GetOSReleaseWithContext(context.Background())
}
func GetOSReleaseWithContext(ctx context.Context) (platform string, version string, err error) {
func GetOSReleaseWithContext(ctx context.Context) (platform, version string, err error) {
contents, err := ReadLines(HostEtcWithContext(ctx, "os-release"))
if err != nil {
return "", "", nil // return empty

View File

@ -33,7 +33,7 @@ func CallLsofWithContext(ctx context.Context, invoke Invoker, pid int32, args ..
var ret []string
for _, l := range lines[1:] {
if len(l) == 0 {
if l == "" {
continue
}
ret = append(ret, l)

View File

@ -0,0 +1,53 @@
package common
import (
"errors"
"os"
"sync"
"syscall"
)
var bufferPool = sync.Pool{
New: func() any {
b := make([]byte, syscall.PathMax)
return &b
},
}
// The following three functions are copied from stdlib.
// ignoringEINTR2 is ignoringEINTR, but returning an additional value.
func ignoringEINTR2[T any](fn func() (T, error)) (T, error) {
for {
v, err := fn()
if !errors.Is(err, syscall.EINTR) {
return v, err
}
}
}
// Many functions in package syscall return a count of -1 instead of 0.
// Using fixCount(call()) instead of call() corrects the count.
func fixCount(n int, err error) (int, error) {
if n < 0 {
n = 0
}
return n, err
}
// Readlink behaves like os.Readlink but caches the buffer passed to syscall.Readlink.
func Readlink(name string) (string, error) {
b := bufferPool.Get().(*[]byte)
n, err := ignoringEINTR2(func() (int, error) {
return fixCount(syscall.Readlink(name, *b))
})
if err != nil {
bufferPool.Put(b)
return "", &os.PathError{Op: "readlink", Path: name, Err: err}
}
result := string((*b)[:n])
bufferPool.Put(b)
return result, nil
}

View File

@ -11,10 +11,14 @@ import (
// https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex
// https://learn.microsoft.com/en-us/windows/win32/api/psapi/ns-psapi-performance_information
type ExVirtualMemory struct {
CommitLimit uint64 `json:"commitLimit"`
CommitTotal uint64 `json:"commitTotal"`
VirtualTotal uint64 `json:"virtualTotal"`
VirtualAvail uint64 `json:"virtualAvail"`
CommitLimit uint64 `json:"commitLimit"`
CommitTotal uint64 `json:"commitTotal"`
VirtualTotal uint64 `json:"virtualTotal"`
VirtualAvail uint64 `json:"virtualAvail"`
PhysTotal uint64 `json:"physTotal"`
PhysAvail uint64 `json:"physAvail"`
PageFileTotal uint64 `json:"pageFileTotal"`
PageFileAvail uint64 `json:"pageFileAvail"`
}
type ExWindows struct{}
@ -44,10 +48,14 @@ func (e *ExWindows) VirtualMemory() (*ExVirtualMemory, error) {
}
ret := &ExVirtualMemory{
CommitLimit: perfInfo.commitLimit * perfInfo.pageSize,
CommitTotal: perfInfo.commitTotal * perfInfo.pageSize,
VirtualTotal: memInfo.ullTotalVirtual,
VirtualAvail: memInfo.ullAvailVirtual,
CommitLimit: perfInfo.commitLimit * perfInfo.pageSize,
CommitTotal: perfInfo.commitTotal * perfInfo.pageSize,
VirtualTotal: memInfo.ullTotalVirtual,
VirtualAvail: memInfo.ullAvailVirtual,
PhysTotal: memInfo.ullTotalPhys,
PhysAvail: memInfo.ullAvailPhys,
PageFileTotal: memInfo.ullTotalPageFile,
PageFileAvail: memInfo.ullAvailPageFile,
}
return ret, nil

View File

@ -94,7 +94,7 @@ type ConntrackStat struct {
SearchRestart uint32 `json:"searchRestart"` // Conntrack table lookups restarted due to hashtable resizes
}
func NewConntrackStat(e uint32, s uint32, f uint32, n uint32, inv uint32, ign uint32, del uint32, dlst uint32, ins uint32, insfail uint32, drop uint32, edrop uint32, ie uint32, en uint32, ec uint32, ed uint32, sr uint32) *ConntrackStat {
func NewConntrackStat(e, s, f, n, inv, ign, del, dlst, ins, insfail, drop, edrop, ie, en, ec, ed, sr uint32) *ConntrackStat {
return &ConntrackStat{
Entries: e,
Searched: s,
@ -273,7 +273,7 @@ func getIOCountersAll(n []IOCountersStat) []IOCountersStat {
return []IOCountersStat{r}
}
// NetIOCounters returns network I/O statistics for every network
// IOCounters returns network I/O statistics for every network
// interface installed on the system. If pernic argument is false,
// return only sum of all information (which name is 'all'). If true,
// every network interface installed on the system is returned
@ -296,7 +296,7 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
return ProtoCountersWithContext(context.Background(), protocols)
}
// NetFilterCounters returns iptables conntrack statistics
// FilterCounters returns iptables conntrack statistics
// the currently in use conntrack count and the max.
// If the file does not exist or is invalid it will return nil.
func FilterCounters() ([]FilterStat, error) {
@ -349,7 +349,7 @@ func ConnectionsPidMax(kind string, pid int32, maxConn int) ([]ConnectionStat, e
// Pids retunres all pids.
// Note: this is a copy of process_linux.Pids()
// FIXME: Import process occures import cycle.
// FIXME: Import process occurs import cycle.
// move to common made other platform breaking. Need consider.
func Pids() ([]int32, error) {
return PidsWithContext(context.Background())

View File

@ -83,7 +83,7 @@ var portMatch = regexp.MustCompile(`(.*)\.(\d+)$`)
// This function only works for netstat returning addresses with a "."
// before the port (0.0.0.0.22 instead of 0.0.0.0:22).
func parseNetstatAddr(local string, remote string, family uint32) (laddr Addr, raddr Addr, err error) {
func parseNetstatAddr(local, remote string, family uint32) (laddr, raddr Addr, err error) {
parse := func(l string) (Addr, error) {
matches := portMatch.FindStringSubmatch(l)
if matches == nil {
@ -183,7 +183,7 @@ func hasCorrectInetProto(kind, proto string) bool {
return false
}
func parseNetstatA(output string, kind string) ([]ConnectionStat, error) {
func parseNetstatA(output, kind string) ([]ConnectionStat, error) {
var ret []ConnectionStat
lines := strings.Split(string(output), "\n")

View File

@ -540,7 +540,7 @@ func PidsWithContext(ctx context.Context) ([]int32, error) {
// Note: the following is based off process_linux structs and methods
// we need these to fetch the owner of a process ID
// FIXME: Import process occures import cycle.
// FIXME: Import process occurs import cycle.
// see remarks on pids()
type process struct {
Pid int32 `json:"pid"`
@ -793,7 +793,7 @@ func processUnix(file string, kind netConnectionKindType, inodes map[string][]in
return ret, nil
}
func updateMap(src map[string][]inodeMap, add map[string][]inodeMap) map[string][]inodeMap {
func updateMap(src, add map[string][]inodeMap) map[string][]inodeMap {
for key, value := range add {
a, exists := src[key]
if !exists {

View File

@ -217,7 +217,7 @@ func parseNetstatLine(line string) (ConnectionStat, error) {
return n, nil
}
func parseNetstatAddr(local string, remote string, family uint32) (laddr Addr, raddr Addr, err error) {
func parseNetstatAddr(local, remote string, family uint32) (laddr, raddr Addr, err error) {
parse := func(l string) (Addr, error) {
matches := portMatch.FindStringSubmatch(l)
if matches == nil {
@ -260,11 +260,7 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat,
switch strings.ToLower(kind) {
default:
fallthrough
case "":
fallthrough
case "all":
fallthrough
case "inet":
case "", "all", "inet":
// nothing to add
case "inet4":
args = append(args, "-finet")

View File

@ -29,11 +29,7 @@ func ConnectionsPidWithContext(ctx context.Context, kind string, pid int32) ([]C
switch strings.ToLower(kind) {
default:
fallthrough
case "":
fallthrough
case "all":
fallthrough
case "inet":
case "", "all", "inet":
args = append(args, "tcp", "-i", "udp")
case "inet4":
args = append(args, "4")
@ -135,7 +131,7 @@ func parseNetLine(line string) (ConnectionStat, error) {
return n, nil
}
func parseNetAddr(line string) (laddr Addr, raddr Addr, err error) {
func parseNetAddr(line string) (laddr, raddr Addr, err error) {
parse := func(l string) (Addr, error) {
host, port, err := net.SplitHostPort(l)
if err != nil {

View File

@ -45,7 +45,8 @@ func pidsWithContext(_ context.Context) ([]int32, error) {
return ret, err
}
for _, proc := range kprocs {
for i := range kprocs {
proc := &kprocs[i]
ret = append(ret, int32(proc.Proc.P_pid))
}
@ -74,7 +75,7 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) {
if err != nil {
return "", err
}
if len(cmdName) > 0 {
if cmdName != "" {
extendedName := filepath.Base(cmdName)
if strings.HasPrefix(extendedName, p.name) {
name = extendedName
@ -238,7 +239,7 @@ func (p *Process) getKProc() (*unix.KinfoProc, error) {
// Return value deletes Header line(you must not input wrong arg).
// And splited by Space. Caller have responsibility to manage.
// If passed arg pid is 0, get information from all process.
func callPsWithContext(ctx context.Context, arg string, pid int32, threadOption bool, nameOption bool) ([][]string, error) {
func callPsWithContext(ctx context.Context, arg string, pid int32, threadOption, nameOption bool) ([][]string, error) {
var cmd []string
switch {
case pid == 0: // will get from all processes.
@ -396,7 +397,7 @@ func (p *Process) cmdlineSlice() ([]string, error) {
// of the process.
for _, arg := range args[1:] {
argStr = string(arg)
if len(argStr) > 0 {
if argStr != "" {
if nargs > 0 {
argSlice = append(argSlice, argStr)
nargs--

View File

@ -358,7 +358,7 @@ func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) {
if err != nil {
continue
}
if int32(ppid) == p.Pid {
if ppid == int64(p.Pid) {
np, err := NewProcessWithContext(ctx, int32(pid))
if err != nil {
continue
@ -372,15 +372,7 @@ func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) {
func (p *Process) OpenFilesWithContext(ctx context.Context) ([]OpenFilesStat, error) {
_, ofs, err := p.fillFromfdWithContext(ctx)
if err != nil {
return nil, err
}
ret := make([]OpenFilesStat, len(ofs))
for i, o := range ofs {
ret[i] = *o
}
return ret, nil
return ofs, err
}
func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionStat, error) {
@ -629,17 +621,17 @@ func (p *Process) fillFromfdListWithContext(ctx context.Context) (string, []stri
}
// Get num_fds from /proc/(pid)/fd
func (p *Process) fillFromfdWithContext(ctx context.Context) (int32, []*OpenFilesStat, error) {
func (p *Process) fillFromfdWithContext(ctx context.Context) (int32, []OpenFilesStat, error) {
statPath, fnames, err := p.fillFromfdListWithContext(ctx)
if err != nil {
return 0, nil, err
}
numFDs := int32(len(fnames))
var openfiles []*OpenFilesStat
openfiles := make([]OpenFilesStat, 0, numFDs)
for _, fd := range fnames {
fpath := filepath.Join(statPath, fd)
filepath, err := os.Readlink(fpath)
path, err := common.Readlink(fpath)
if err != nil {
continue
}
@ -647,8 +639,8 @@ func (p *Process) fillFromfdWithContext(ctx context.Context) (int32, []*OpenFile
if err != nil {
return numFDs, openfiles, err
}
o := &OpenFilesStat{
Path: filepath,
o := OpenFilesStat{
Path: path,
Fd: t,
}
openfiles = append(openfiles, o)

View File

@ -358,7 +358,7 @@ func (p *Process) getKProc() (*KinfoProc, error) {
return &k, nil
}
func callKernProcSyscall(op int32, arg int32) ([]byte, uint64, error) {
func callKernProcSyscall(op, arg int32) ([]byte, uint64, error) {
mib := []int32{CTLKern, KernProc, op, arg, sizeOfKinfoProc, 0}
mibptr := unsafe.Pointer(&mib[0])
miblen := uint64(len(mib))

View File

@ -67,7 +67,8 @@ func getTerminalMap() (map[uint64]string, error) {
for _, name := range termfiles {
stat := unix.Stat_t{}
if err = unix.Stat(name, &stat); err != nil {
err = unix.Stat(name, &stat)
if err != nil {
return nil, err
}
rdev := uint64(stat.Rdev)

View File

@ -882,7 +882,8 @@ func getFromSnapProcess(pid int32) (int32, int32, string, error) { //nolint:unpa
defer windows.CloseHandle(snap)
var pe32 windows.ProcessEntry32
pe32.Size = uint32(unsafe.Sizeof(pe32))
if err = windows.Process32First(snap, &pe32); err != nil {
err = windows.Process32First(snap, &pe32)
if err != nil {
return 0, 0, "", err
}
for {