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

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2025-11-01 03:08:38 +00:00
committed by GitHub
parent 8aea109e42
commit b309044006
13 changed files with 60 additions and 145 deletions

2
go.mod
View File

@@ -57,7 +57,7 @@ require (
github.com/opencontainers/selinux v1.12.0 github.com/opencontainers/selinux v1.12.0
github.com/openshift/imagebuilder v1.2.19 github.com/openshift/imagebuilder v1.2.19
github.com/rootless-containers/rootlesskit/v2 v2.3.5 github.com/rootless-containers/rootlesskit/v2 v2.3.5
github.com/shirou/gopsutil/v4 v4.25.9 github.com/shirou/gopsutil/v4 v4.25.10
github.com/sirupsen/logrus v1.9.3 github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.10.1 github.com/spf13/cobra v1.10.1
github.com/spf13/pflag v1.0.10 github.com/spf13/pflag v1.0.10

4
go.sum
View File

@@ -361,8 +361,8 @@ github.com/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c
github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE= github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/shirou/gopsutil/v4 v4.25.9 h1:JImNpf6gCVhKgZhtaAHJ0serfFGtlfIlSC08eaKdTrU= github.com/shirou/gopsutil/v4 v4.25.10 h1:at8lk/5T1OgtuCp+AwrDofFRjnvosn0nkN2OLQ6g8tA=
github.com/shirou/gopsutil/v4 v4.25.9/go.mod h1:gxIxoC+7nQRwUl/xNhutXlD8lq+jxTgpIkEf3rADHL8= github.com/shirou/gopsutil/v4 v4.25.10/go.mod h1:+kSwyC8DRUD9XXEHCAFjK+0nuArFJM0lva+StQAcskM=
github.com/sigstore/fulcio v1.7.1 h1:RcoW20Nz49IGeZyu3y9QYhyyV3ZKQ85T+FXPKkvE+aQ= github.com/sigstore/fulcio v1.7.1 h1:RcoW20Nz49IGeZyu3y9QYhyyV3ZKQ85T+FXPKkvE+aQ=
github.com/sigstore/fulcio v1.7.1/go.mod h1:7lYY+hsd8Dt+IvKQRC+KEhWpCZ/GlmNvwIa5JhypMS8= github.com/sigstore/fulcio v1.7.1/go.mod h1:7lYY+hsd8Dt+IvKQRC+KEhWpCZ/GlmNvwIa5JhypMS8=
github.com/sigstore/protobuf-specs v0.4.1 h1:5SsMqZbdkcO/DNHudaxuCUEjj6x29tS2Xby1BxGU7Zc= github.com/sigstore/protobuf-specs v0.4.1 h1:5SsMqZbdkcO/DNHudaxuCUEjj6x29tS2Xby1BxGU7Zc=

View File

@@ -8,12 +8,14 @@ import (
"errors" "errors"
"fmt" "fmt"
"math/bits" "math/bits"
"path/filepath"
"strconv" "strconv"
"strings"
"syscall" "syscall"
"unsafe" "unsafe"
"github.com/yusufpapurcu/wmi"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
"github.com/shirou/gopsutil/v4/internal/common" "github.com/shirou/gopsutil/v4/internal/common"
) )
@@ -75,6 +77,8 @@ const (
smbiosEndOfTable = 127 // Minimum length for processor structure smbiosEndOfTable = 127 // Minimum length for processor structure
smbiosTypeProcessor = 4 // SMBIOS Type 4: Processor Information smbiosTypeProcessor = 4 // SMBIOS Type 4: Processor Information
smbiosProcessorMinLength = 0x18 // Minimum length for processor structure smbiosProcessorMinLength = 0x18 // Minimum length for processor structure
centralProcessorRegistryKey = `HARDWARE\DESCRIPTION\System\CentralProcessor`
) )
type relationship uint32 type relationship uint32
@@ -179,61 +183,27 @@ func getProcessorPowerInformation(ctx context.Context) ([]processorPowerInformat
func InfoWithContext(ctx context.Context) ([]InfoStat, error) { func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
var ret []InfoStat var ret []InfoStat
var dst []win32_Processor
q := wmi.CreateQuery(&dst, "")
if err := common.WMIQueryWithContext(ctx, q, &dst); err != nil {
return ret, err
}
var procID string
for i, l := range dst {
procID = ""
if l.ProcessorID != nil {
procID = *l.ProcessorID
}
cpu := InfoStat{
CPU: int32(i),
Family: strconv.FormatUint(uint64(l.Family), 10),
VendorID: l.Manufacturer,
ModelName: l.Name,
Cores: int32(l.NumberOfLogicalProcessors), // TO BE REMOVED, set by getSystemLogicalProcessorInformationEx
PhysicalID: procID,
Mhz: float64(l.MaxClockSpeed),
Flags: []string{},
}
ret = append(ret, cpu)
}
processorPackages, err := getSystemLogicalProcessorInformationEx(relationProcessorPackage) processorPackages, err := getSystemLogicalProcessorInformationEx(relationProcessorPackage)
if err != nil { if err != nil {
// return an error whem wmi will be removed return ret, fmt.Errorf("failed to get processor package information: %w", err)
// return ret, fmt.Errorf("failed to get processor package information: %w", err)
return ret, nil
}
if len(processorPackages) != len(ret) {
// this should never happen, but it's kept for safety until wmi is removed
return ret, nil
} }
ppis, powerInformationErr := getProcessorPowerInformation(ctx) ppis, powerInformationErr := getProcessorPowerInformation(ctx)
if powerInformationErr != nil { if powerInformationErr != nil {
// return an error whem wmi will be removed return ret, fmt.Errorf("failed to get processor power information: %w", err)
// return ret, fmt.Errorf("failed to get processor power information: %w", err)
return ret, nil
} }
family, processorId, smBIOSErr := getSMBIOSProcessorInfo() family, processorId, smBIOSErr := getSMBIOSProcessorInfo()
if smBIOSErr != nil { if smBIOSErr != nil {
// return an error whem wmi will be removed return ret, smBIOSErr
// return ret, smBIOSErr
return ret, nil
} }
for i, pkg := range processorPackages { for i, pkg := range processorPackages {
logicalCount := 0 logicalCount := 0
maxMhz := 0 maxMhz := 0
model := ""
vendorId := ""
// iterate over each set bit in the package affinity mask
for _, ga := range pkg.processor.groupMask { for _, ga := range pkg.processor.groupMask {
g := int(ga.group) g := int(ga.group)
forEachSetBit64(uint64(ga.mask), func(bit int) { forEachSetBit64(uint64(ga.mask), func(bit int) {
@@ -246,12 +216,26 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
maxMhz = m maxMhz = m
} }
} }
registryKeyPath := filepath.Join(centralProcessorRegistryKey, strconv.Itoa(globalLpl))
key, err := registry.OpenKey(registry.LOCAL_MACHINE, registryKeyPath, registry.QUERY_VALUE|registry.READ)
if err == nil {
model = getRegistryStringValueIfUnset(key, "ProcessorNameString", model)
vendorId = getRegistryStringValueIfUnset(key, "VendorIdentifier", vendorId)
_ = key.Close()
}
}) })
} }
ret[i].Mhz = float64(maxMhz) ret = append(ret, InfoStat{
ret[i].Cores = int32(logicalCount) CPU: int32(i),
ret[i].Family = strconv.FormatUint(uint64(family), 10) Family: strconv.FormatUint(uint64(family), 10),
ret[i].PhysicalID = processorId VendorID: vendorId,
ModelName: model,
Cores: int32(logicalCount),
PhysicalID: processorId,
Mhz: float64(maxMhz),
Flags: []string{},
})
} }
return ret, nil return ret, nil
@@ -461,6 +445,17 @@ func getPhysicalCoreCount() (int, error) {
return len(infos), err return len(infos), err
} }
func getRegistryStringValueIfUnset(key registry.Key, keyName, value string) string {
if value != "" {
return value
}
val, _, err := key.GetStringValue(keyName)
if err == nil {
return strings.TrimSpace(val)
}
return ""
}
func CountsWithContext(_ context.Context, logical bool) (int, error) { func CountsWithContext(_ context.Context, logical bool) (int, error) {
if logical { if logical {
// Get logical processor count https://github.com/giampaolo/psutil/blob/d01a9eaa35a8aadf6c519839e987a49d8be2d891/psutil/_psutil_windows.c#L97 // Get logical processor count https://github.com/giampaolo/psutil/blob/d01a9eaa35a8aadf6c519839e987a49d8be2d891/psutil/_psutil_windows.c#L97

View File

@@ -442,7 +442,7 @@ func HostRootWithContext(ctx context.Context, combineWith ...string) string {
} }
// getSysctrlEnv sets LC_ALL=C in a list of env vars for use when running // getSysctrlEnv sets LC_ALL=C in a list of env vars for use when running
// sysctl commands (see DoSysctrl). // sysctl commands.
func getSysctrlEnv(env []string) []string { func getSysctrlEnv(env []string) []string {
foundLC := false foundLC := false
for i, line := range env { for i, line := range env {

View File

@@ -4,32 +4,14 @@
package common package common
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"os"
"os/exec"
"strings"
"unsafe" "unsafe"
"github.com/ebitengine/purego" "github.com/ebitengine/purego"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
func DoSysctrlWithContext(ctx context.Context, mib string) ([]string, error) {
cmd := exec.CommandContext(ctx, "sysctl", "-n", mib)
cmd.Env = getSysctrlEnv(os.Environ())
out, err := cmd.Output()
if err != nil {
return []string{}, err
}
v := strings.Replace(string(out), "{ ", "", 1)
v = strings.Replace(string(v), " }", "", 1)
values := strings.Fields(string(v))
return values, nil
}
func CallSyscall(mib []int32) ([]byte, uint64, error) { func CallSyscall(mib []int32) ([]byte, uint64, error) {
miblen := uint64(len(mib)) miblen := uint64(len(mib))

View File

@@ -5,9 +5,6 @@ package common
import ( import (
"fmt" "fmt"
"os"
"os/exec"
"strings"
"unsafe" "unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@@ -28,20 +25,6 @@ func SysctlUint(mib string) (uint64, error) {
return 0, fmt.Errorf("unexpected size: %s, %d", mib, len(buf)) return 0, fmt.Errorf("unexpected size: %s, %d", mib, len(buf))
} }
func DoSysctrl(mib string) ([]string, error) {
cmd := exec.Command("sysctl", "-n", mib)
cmd.Env = getSysctrlEnv(os.Environ())
out, err := cmd.Output()
if err != nil {
return []string{}, err
}
v := strings.Replace(string(out), "{ ", "", 1)
v = strings.Replace(string(v), " }", "", 1)
values := strings.Fields(string(v))
return values, nil
}
func CallSyscall(mib []int32) ([]byte, uint64, error) { func CallSyscall(mib []int32) ([]byte, uint64, error) {
mibptr := unsafe.Pointer(&mib[0]) mibptr := unsafe.Pointer(&mib[0])
miblen := uint64(len(mib)) miblen := uint64(len(mib))

View File

@@ -7,7 +7,6 @@ import (
"context" "context"
"errors" "errors"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@@ -20,20 +19,6 @@ import (
// cachedBootTime must be accessed via atomic.Load/StoreUint64 // cachedBootTime must be accessed via atomic.Load/StoreUint64
var cachedBootTime uint64 var cachedBootTime uint64
func DoSysctrl(mib string) ([]string, error) {
cmd := exec.Command("sysctl", "-n", mib)
cmd.Env = getSysctrlEnv(os.Environ())
out, err := cmd.Output()
if err != nil {
return []string{}, err
}
v := strings.Replace(string(out), "{ ", "", 1)
v = strings.Replace(string(v), " }", "", 1)
values := strings.Fields(string(v))
return values, nil
}
func NumProcs() (uint64, error) { func NumProcs() (uint64, error) {
return NumProcsWithContext(context.Background()) return NumProcsWithContext(context.Background())
} }

View File

@@ -4,28 +4,11 @@
package common package common
import ( import (
"os"
"os/exec"
"strings"
"unsafe" "unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
func DoSysctrl(mib string) ([]string, error) {
cmd := exec.Command("sysctl", "-n", mib)
cmd.Env = getSysctrlEnv(os.Environ())
out, err := cmd.Output()
if err != nil {
return []string{}, err
}
v := strings.Replace(string(out), "{ ", "", 1)
v = strings.Replace(string(v), " }", "", 1)
values := strings.Fields(string(v))
return values, nil
}
func CallSyscall(mib []int32) ([]byte, uint64, error) { func CallSyscall(mib []int32) ([]byte, uint64, error) {
mibptr := unsafe.Pointer(&mib[0]) mibptr := unsafe.Pointer(&mib[0])
miblen := uint64(len(mib)) miblen := uint64(len(mib))

View File

@@ -4,28 +4,11 @@
package common package common
import ( import (
"os"
"os/exec"
"strings"
"unsafe" "unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
func DoSysctrl(mib string) ([]string, error) {
cmd := exec.Command("sysctl", "-n", mib)
cmd.Env = getSysctrlEnv(os.Environ())
out, err := cmd.Output()
if err != nil {
return []string{}, err
}
v := strings.Replace(string(out), "{ ", "", 1)
v = strings.Replace(string(v), " }", "", 1)
values := strings.Fields(string(v))
return values, nil
}
func CallSyscall(mib []int32) ([]byte, uint64, error) { func CallSyscall(mib []int32) ([]byte, uint64, error) {
mibptr := unsafe.Pointer(&mib[0]) mibptr := unsafe.Pointer(&mib[0])
miblen := uint64(len(mib)) miblen := uint64(len(mib))

View File

@@ -1,7 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
package common package common
import "fmt" import (
"fmt"
"strings"
)
const ( const (
maxWarnings = 100 // An arbitrary limit to avoid excessive memory usage, it has no sense to store hundreds of errors maxWarnings = 100 // An arbitrary limit to avoid excessive memory usage, it has no sense to store hundreds of errors
@@ -33,9 +36,11 @@ func (w *Warnings) Reference() error {
func (w *Warnings) Error() string { func (w *Warnings) Error() string {
if w.Verbose { if w.Verbose {
str := "" str := ""
var sb strings.Builder
for i, e := range w.List { for i, e := range w.List {
str += fmt.Sprintf("\tError %d: %s\n", i, e.Error()) sb.WriteString(fmt.Sprintf("\tError %d: %s\n", i, e.Error()))
} }
str += sb.String()
if w.tooManyErrors { if w.tooManyErrors {
str += fmt.Sprintf("\t%s\n", tooManyErrorsMessage) str += fmt.Sprintf("\t%s\n", tooManyErrorsMessage)
} }

View File

@@ -50,26 +50,25 @@ func IOCountersByFileWithContext(_ context.Context, pernic bool, filename string
return nil, err return nil, err
} }
parts := make([]string, 2)
statlen := len(lines) - 1 statlen := len(lines) - 1
ret := make([]IOCountersStat, 0, statlen) ret := make([]IOCountersStat, 0, statlen)
for _, line := range lines[2:] { for _, line := range lines[2:] {
// Split interface name and stats data at the last ":"
separatorPos := strings.LastIndex(line, ":") separatorPos := strings.LastIndex(line, ":")
if separatorPos == -1 { if separatorPos == -1 {
continue continue
} }
parts[0] = line[0:separatorPos] interfacePart := line[0:separatorPos]
parts[1] = line[separatorPos+1:] statsPart := line[separatorPos+1:]
interfaceName := strings.TrimSpace(parts[0]) interfaceName := strings.TrimSpace(interfacePart)
if interfaceName == "" { if interfaceName == "" {
continue continue
} }
fields := strings.Fields(strings.TrimSpace(parts[1])) fields := strings.Fields(strings.TrimSpace(statsPart))
bytesRecv, err := strconv.ParseUint(fields[0], 10, 64) bytesRecv, err := strconv.ParseUint(fields[0], 10, 64)
if err != nil { if err != nil {
return ret, err return ret, err
@@ -610,7 +609,7 @@ func getProcInodesAllWithContext(ctx context.Context, root string, maxConn int)
return ret, nil return ret, nil
} }
// decodeAddress decode addresse represents addr in proc/net/* // decodeAddress decode address represents addr in proc/net/*
// ex: // ex:
// "0500000A:0016" -> "10.0.0.5", 22 // "0500000A:0016" -> "10.0.0.5", 22
// "0085002452100113070057A13F025401:0035" -> "2400:8500:1301:1052:a157:7:154:23f", 53 // "0085002452100113070057A13F025401:0035" -> "2400:8500:1301:1052:a157:7:154:23f", 53

View File

@@ -237,7 +237,7 @@ func (p *Process) getKProc() (*unix.KinfoProc, error) {
// call ps command. // call ps command.
// Return value deletes Header line(you must not input wrong arg). // Return value deletes Header line(you must not input wrong arg).
// And splited by Space. Caller have responsibility to manage. // And split by Space. Caller have responsibility to manage.
// If passed arg pid is 0, get information from all process. // If passed arg pid is 0, get information from all process.
func callPsWithContext(ctx context.Context, arg string, pid int32, threadOption, nameOption bool) ([][]string, error) { func callPsWithContext(ctx context.Context, arg string, pid int32, threadOption, nameOption bool) ([][]string, error) {
var cmd []string var cmd []string

4
vendor/modules.txt vendored
View File

@@ -605,8 +605,8 @@ github.com/secure-systems-lab/go-securesystemslib/encrypted
# github.com/segmentio/ksuid v1.0.4 # github.com/segmentio/ksuid v1.0.4
## explicit; go 1.12 ## explicit; go 1.12
github.com/segmentio/ksuid github.com/segmentio/ksuid
# github.com/shirou/gopsutil/v4 v4.25.9 # github.com/shirou/gopsutil/v4 v4.25.10
## explicit; go 1.23.0 ## explicit; go 1.24.0
github.com/shirou/gopsutil/v4/common github.com/shirou/gopsutil/v4/common
github.com/shirou/gopsutil/v4/cpu github.com/shirou/gopsutil/v4/cpu
github.com/shirou/gopsutil/v4/internal/common github.com/shirou/gopsutil/v4/internal/common