Merge pull request #1596 from shirou/feat/v4.24.0-alpha

[v4] Implements v4 for v4.24.0-alpha
tags/v4.24.0-beta
shirou 11 months ago committed by GitHub
commit 68ea86334a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -14,6 +14,8 @@ package:net:
- net/*
package:process:
- process/*
package:sensors:
- sensors/*
package:winservices:
- winservices/*
os:linux:

@ -13,7 +13,7 @@ jobs:
run: |
versions=$(curl -s 'https://go.dev/dl/?mode=json' | jq -c 'map(.version[2:])')
echo "::set-output name=value::${versions}"
test_v3_module:
test:
needs: go-versions
strategy:
fail-fast: false

@ -5,7 +5,13 @@
This is a port of psutil (https://github.com/giampaolo/psutil). The
challenge is porting all psutil functions on some architectures.
## v3 migration
## migration
### v4 migration
See v4 release note.
### v3 migration
From v3.20.10, gopsutil becomes v3 which breaks backwards compatibility.
See [v3Changes.md](_tools/v3migration/v3Changes.md) for more detailed changes.
@ -15,10 +21,10 @@ See [v3Changes.md](_tools/v3migration/v3Changes.md) for more detailed changes.
gopsutil tag policy is almost same as Semantic Versioning, but
automatically increases like [Ubuntu versioning](https://calver.org/).
For example, v2.17.04 means
For example, v4.24.04 means
- v2: major version
- 17: release year, 2017
- v4: major version
- 24: release year, 2024
- 04: release month
gopsutil aims to keep backwards compatibility until major version change.
@ -52,7 +58,7 @@ package main
import (
"fmt"
"github.com/shirou/gopsutil/v3/mem"
"github.com/shirou/gopsutil/v4/mem"
// "github.com/shirou/gopsutil/mem" // to use v2
)
@ -122,11 +128,11 @@ Be very careful that enabling the cache may cause inconsistencies. For example,
## Documentation
See https://pkg.go.dev/github.com/shirou/gopsutil/v3 or https://godocs.io/github.com/shirou/gopsutil/v3
See https://pkg.go.dev/github.com/shirou/gopsutil/v4 or https://godocs.io/github.com/shirou/gopsutil/v4
## Requirements
- go1.16 or above is required.
- go1.20 or above is required.
## More Info

@ -1,18 +0,0 @@
# v2 to v3 changes
- v3 is in the `v3` directory
- [process] RLimit is now uint64 ([#364](https://github.com/shirou/gopsutil/issues/364))
- [process] Remove process.NetIOCounters ([#429](https://github.com/shirou/gopsutil/issues/429))
- [docker] fix typo of memoryLimitInBbytes ([#464](https://github.com/shirou/gopsutil/issues/464))
- [mem] VirtualMemoryStat JSON fields capitalization ([#545](https://github.com/shirou/gopsutil/issues/545))
- various JSON field name and some of Variable name have been changed. see v3migration.sh
- [all] various kind of platform dependent values/constants such as process.GetWin32Proc is now private. see v3migration.sh
- [process] process.Status() now returns []string. and status string is "Running", not just "R". defined in process.go. ([#596](https://github.com/shirou/gopsutil/issues/596))
- [docker] `CgroupCPU()` now returns `*CgroupCPUStat` with Usage ([#590](https://github.com/shirou/gopsutil/issues/590) and [#581](https://github.com/shirou/gopsutil/issues/581))
- [disk] `disk.Opts` is now string[], not string. (related to [#955](https://github.com/shirou/gopsutil/issues/955))
- [host] Fixed temperature sensors detection in Linux ([#905](https://github.com/shirou/gopsutil/issues/905))
- [disk] `GetDiskSerialNumber()` is now `SerialNumber()` and spread to all platforms
- [disk] `GetLabel ()` is now `Label()` and spread to all platform
- [net] Change net.InterfaceStat.Addrs to InterfaceAddrList ([#226](https://github.com/shirou/gopsutil/issues/226))
- [cpu] Removed windows-specific `ProcInfo()`

@ -1,106 +0,0 @@
package main
import (
"flag"
"fmt"
"go/ast"
"go/format"
"go/parser"
"go/token"
"log"
"os"
"golang.org/x/tools/go/ast/astutil"
)
// https://github.com/shirou/gopsutil/issues/429
func issue429() error {
f := func(filename string) error {
fset := token.NewFileSet()
expr, err := parser.ParseFile(fset, filename, nil, parser.ParseComments)
if err != nil {
return err
}
n := astutil.Apply(expr, func(cr *astutil.Cursor) bool {
if cr.Name() == "Decls" {
switch n := cr.Node().(type) {
case *ast.FuncDecl:
if n.Name.Name == "NetIOCounters" || n.Name.Name == ("NetIOCountersWithContext") {
cr.Delete()
}
}
}
return true
}, nil)
return replace(filename, fset, n)
}
root := "process/"
fnames := []string{"process.go", "process_darwin.go", "process_fallback.go", "process_freebsd.go", "process_linux.go", "process_openbsd.go", "process_bsd.go", "process_posix.go", "process_windows.go", "process_test.go"}
for _, fname := range fnames {
if err := f(root + fname); err != nil {
log.Fatalln("run 429:", err)
}
}
return nil
}
func issueRemoveUnusedValue() error {
f := func(filename string) error {
fset := token.NewFileSet()
expr, err := parser.ParseFile(fset, filename, nil, parser.ParseComments)
if err != nil {
return err
}
n := astutil.Apply(expr, func(cr *astutil.Cursor) bool {
if cr.Name() == "Decls" {
switch n := cr.Node().(type) {
case *ast.GenDecl:
if n.Tok != token.TYPE {
break
}
ts := n.Specs[0].(*ast.TypeSpec)
if ts.Name.Name == "SystemProcessInformation" {
cr.Delete()
}
}
}
return true
}, nil)
return replace(filename, fset, n)
}
if err := f("process/process_windows.go"); err != nil {
log.Fatalln("run 429:", err)
}
return nil
}
func replace(filename string, fset *token.FileSet, n ast.Node) error {
if err := os.Remove(filename); err != nil {
return err
}
fp, err := os.Create(filename)
if err != nil {
return err
}
defer fp.Close()
if err := format.Node(fp, fset, n); err != nil {
return err
}
fp.WriteString("\n")
return nil
}
func main() {
flag.Parse()
for _, n := range flag.Args() {
fmt.Println("issue:" + n)
switch n {
case "429":
issue429()
case "issueRemoveUnusedValue":
issueRemoveUnusedValue()
}
}
}

@ -1,171 +0,0 @@
#!/usr/bin/env bash
set -eu
# this scripts is used when migrating v2 to v3.
# usage: cd ${GOPATH}/src/github.com/shirou/gopsutil && bash tools/v3migration/v3migration.sh
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)"
ROOT=$(cd "${DIR}"/../.. && pwd)
## 1. refresh
cd "${ROOT}"
/bin/rm -rf v3
## 2. copy directories
# docker is removed, #464 will be fixed
mkdir -p v3
cp -rp cpu disk docker host internal load mem net process winservices v3
cp Makefile v3
# build migartion tool
go build -o v3/v3migration "${DIR}"/v3migration.go
V3DIR=$(cd "${ROOT}"/v3 && pwd)
cd "${V3DIR}"
## 3. mod
go mod init
### change import path
find . -name "*.go" -print0 | xargs -0 -I@ sed -i 's|"github.com/shirou/gopsutil/|"github.com/shirou/gopsutil/v3/|g' @
############ Issues
# #429 process.NetIOCounters is pointless on Linux
./v3migration "$(pwd)" 429
sed -i '/NetIOCounters/d' process/process.go
sed -i "/github.com\/shirou\/gopsutil\/v3\/net/d" process/process_bsd.go
# #464 CgroupMem : fix typo and wrong file names
sed -i 's|memoryLimitInBbytes|memoryLimitInBytes|g' docker/docker.go
sed -i 's|memoryLimitInBbytes|memory.limit_in_bytes|g' docker/docker_linux.go
sed -i 's|memoryFailcnt|memory.failcnt|g' docker/docker_linux.go
# fix #346
sed -i 's/Soft int32/Soft uint64/' process/process.go
sed -i 's/Hard int32/Hard uint64/' process/process.go
sed -i 's| //TODO too small. needs to be uint64||' process/process.go
sed -i 's|limitToInt(val string) (int32, error)|limitToUint(val string) (uint64, error)|' process/process_*.go
sed -i 's|limitToInt|limitToUint|' process/process_*.go
sed -i 's|return int32(res), nil|return uint64(res), nil|' process/process_*.go
sed -i 's|math.MaxInt32|math.MaxUint64|' process/process_*.go
# fix #545
# variable names
sed -i 's|WritebackTmp|WriteBackTmp|g' mem/*.go
sed -i 's|Writeback|WriteBack|g' mem/*.go
sed -i 's|SReclaimable|Sreclaimable|g' mem/*.go
sed -i 's|SUnreclaim|Sunreclaim|g' mem/*.go
sed -i 's|VMallocTotal|VmallocTotal|g' mem/*.go
sed -i 's|VMallocUsed|VmallocUsed|g' mem/*.go
sed -i 's|VMallocChunk|VmallocChunk|g' mem/*.go
# json field name
sed -i 's|hostid|hostId|g' host/host.go
sed -i 's|hostid|hostId|g' host/host_test.go
sed -i 's|sensorTemperature|temperature|g' host/host.go
sed -i 's|sensorTemperature|temperature|g' host/host_test.go
sed -i 's|writeback|writeBack|g' mem/*.go
sed -i 's|writeBacktmp|writeBackTmp|g' mem/*.go
sed -i 's|pagetables|pageTables|g' mem/*.go
sed -i 's|swapcached|swapCached|g' mem/*.go
sed -i 's|commitlimit|commitLimit|g' mem/*.go
sed -i 's|committedas|committedAS|g' mem/*.go
sed -i 's|hightotal|highTotal|g' mem/*.go
sed -i 's|highfree|highFree|g' mem/*.go
sed -i 's|lowtotal|lowTotal|g' mem/*.go
sed -i 's|lowfree|lowFree|g' mem/*.go
sed -i 's|swaptotal|swapTotal|g' mem/*.go
sed -i 's|swapfree|swapFree|g' mem/*.go
sed -i 's|vmalloctotal|vmallocTotal|g' mem/*.go
sed -i 's|vmallocused|vmallocUsed|g' mem/*.go
sed -i 's|vmallocchunk|vmallocChunk|g' mem/*.go
sed -i 's|hugepagestotal|hugePagesTotal|g' mem/*.go
sed -i 's|hugepagesfree|hugePagesFree|g' mem/*.go
sed -i 's|hugepagesize|hugePageSize|g' mem/*.go
sed -i 's|pgin|pgIn|g' mem/*.go
sed -i 's|pgout|pgOut|g' mem/*.go
sed -i 's|pgfault|pgFault|g' mem/*.go
sed -i 's|pgmajfault|pgMajFault|g' mem/*.go
sed -i 's|hardwareaddr|hardwareAddr|g' net/*.go
sed -i 's|conntrackCount|connTrackCount|g' net/*.go
sed -i 's|conntrackMax|connTrackMax|g' net/*.go
sed -i 's|delete_list|deleteList|g' net/*.go
sed -i 's|insert_failed|insertFailed|g' net/*.go
sed -i 's|early_drop|earlyDrop|g' net/*.go
sed -i 's|expect_create|expectCreate|g' net/*.go
sed -i 's|expect_delete|expectDelete|g' net/*.go
sed -i 's|search_restart|searchRestart|g' net/*.go
sed -i 's|icmp_error|icmpError|g' net/*.go
sed -i 's|expect_new|expectNew|g' net/*.go
# fix no more public API/types/constants defined only for some platforms
sed -i 's|CTLKern|ctlKern|g' cpu/*.go
sed -i 's|CPNice|cpNice|g' cpu/*.go
sed -i 's|CPSys|cpSys|g' cpu/*.go
sed -i 's|CPIntr|cpIntr|g' cpu/*.go
sed -i 's|CPIdle|cpIdle|g' cpu/*.go
sed -i 's|CPUStates|cpUStates|g' cpu/*.go
sed -i 's|CTLKern|ctlKern|g' cpu/cpu_openbsd.go
sed -i 's|CTLHw|ctlHw|g' cpu/cpu_openbsd.go
sed -i 's|SMT|sMT|g' cpu/cpu_openbsd.go
sed -i 's|KernCptime|kernCptime|g' cpu/cpu_openbsd.go
sed -i 's|KernCptime2|kernCptime2|g' cpu/cpu_openbsd.go
sed -i 's|Win32_Processor|win32Processor|g' cpu/cpu_windows.go
sed -i 's|DEVSTAT_NO_DATA|devstat_NO_DATA|g' disk/*.go
sed -i 's|DEVSTAT_READ|devstat_READ|g' disk/*.go
sed -i 's|DEVSTAT_WRITE|devstat_WRITE|g' disk/*.go
sed -i 's|DEVSTAT_FREE|devstat_FREE|g' disk/*.go
sed -i 's|Devstat|devstat|g' disk/*.go
sed -i 's|Bintime|bintime|g' disk/*.go
sed -i 's|SectorSize|sectorSize|g' disk/disk_linux.go
sed -i 's|FileFileCompression|fileFileCompression|g' disk/disk_windows.go
sed -i 's|FileReadOnlyVolume|fileReadOnlyVolume|g' disk/disk_windows.go
sed -i 's|USER_PROCESS|user_PROCESS|g' host/host_*.go
sed -i 's|LSB|lsbStruct|g' host/host_linux*
sed -i 's| BcacheStats | bcacheStats |g' mem/*.go
sed -i 's|TCPStatuses|tcpStatuses|g' net/*.go
sed -i 's|CT_ENTRIES|ctENTRIES|g' net/net_linux.go
sed -i 's|CT_SEARCHED|ctSEARCHED|g' net/net_linux.go
sed -i 's|CT_FOUND|ctFOUND|g' net/net_linux.go
sed -i 's|CT_NEW|ctNEW|g' net/net_linux.go
sed -i 's|CT_INVALID|ctINVALID|g' net/net_linux.go
sed -i 's|CT_IGNORE|ctIGNORE|g' net/net_linux.go
sed -i 's|CT_DELETE|ctDELETE|g' net/net_linux.go
sed -i 's|CT_DELETE_LIST|ctDELETE_LIST|g' net/net_linux.go
sed -i 's|CT_INSERT|ctINSERT|g' net/net_linux.go
sed -i 's|CT_INSERT_FAILED|ctINSERT_FAILED|g' net/net_linux.go
sed -i 's|CT_DROP|ctDROP|g' net/net_linux.go
sed -i 's|CT_EARLY_DROP|ctEARLY_DROP|g' net/net_linux.go
sed -i 's|CT_ICMP_ERROR|ctICMP_ERROR|g' net/net_linux.go
sed -i 's|CT_EXPECT_NEW|ctEXPECT_NEW|g' net/net_linux.go
sed -i 's|CT_EXPECT_CREATE|ctEXPECT_CREATE|g' net/net_linux.go
sed -i 's|CT_EXPECT_DELETE|ctEXPECT_DELETE|g' net/net_linux.go
sed -i 's|CT_SEARCH_RESTART|ctSEARCH_RESTART|g' net/net_linux.go
sed -i 's|PageSize|pageSize|g' process/process_*.go
sed -i 's|PrioProcess|prioProcess|g' process/process_*.go
sed -i 's|ClockTicks|clockTicks|g' process/process_*.go
./v3migration "$(pwd)" issueRemoveUnusedValue
############ SHOULD BE FIXED BY HAND

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package common
type EnvKeyType string

@ -1,26 +0,0 @@
#!/bin/sh
# see http://www.songmu.jp/riji/entry/2015-01-15-goveralls-multi-package.html
set -e
# cleanup
cleanup() {
if [ "$tmpprof" != "" ] && [ -f "$tmpprof" ]; then
rm -f "$tmpprof"
fi
exit
}
trap cleanup INT QUIT TERM EXIT
# メインの処理
prof=${1:-".profile.cov"}
echo "mode: count" > "$prof"
gopath1=$(echo "$GOPATH" | cut -d: -f1)
for pkg in $(go list ./...); do
tmpprof="$gopath1/src/$pkg/profile.tmp"
go test -covermode=count -coverprofile="$tmpprof" "$pkg"
if [ -f "$tmpprof" ]; then
tail -n +2 "$tmpprof" >> "$prof"
rm "$tmpprof"
fi
done

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
import (
@ -11,7 +12,7 @@ import (
"sync"
"time"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
// TimesStat contains the amounts of time the CPU has spent performing different

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build aix
// +build aix
package cpu

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build aix && cgo
// +build aix,cgo
package cpu

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build aix && !cgo
// +build aix,!cgo
package cpu
@ -8,7 +8,7 @@ import (
"strconv"
"strings"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build darwin
// +build darwin
package cpu

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build darwin && cgo
// +build darwin,cgo
package cpu

@ -1,9 +1,9 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build darwin && !cgo
// +build darwin,!cgo
package cpu
import "github.com/shirou/gopsutil/v3/internal/common"
import "github.com/shirou/gopsutil/v4/internal/common"
func perCPUTimes() ([]TimesStat, error) {
return []TimesStat{}, common.ErrNotImplementedError

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build darwin
// +build darwin
package cpu
@ -10,7 +10,7 @@ import (
"github.com/shoenig/go-m1cpu"
)
func Test_CpuInfo_AppleSilicon(t *testing.T) {
func TestInfo_AppleSilicon(t *testing.T) {
if !m1cpu.IsAppleSilicon() {
t.Skip("wrong cpu type")
}

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
import (
@ -10,7 +11,7 @@ import (
"strings"
"unsafe"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
)

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build !darwin && !linux && !freebsd && !openbsd && !netbsd && !solaris && !windows && !dragonfly && !plan9 && !aix
// +build !darwin,!linux,!freebsd,!openbsd,!netbsd,!solaris,!windows,!dragonfly,!plan9,!aix
package cpu
@ -7,7 +7,7 @@ import (
"context"
"runtime"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
func Times(percpu bool) ([]TimesStat, error) {

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
import (
@ -10,7 +11,7 @@ import (
"strings"
"unsafe"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
)

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
import (
@ -5,7 +6,7 @@ import (
"runtime"
"testing"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
func TestParseDmesgBoot(t *testing.T) {

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build linux
// +build linux
package cpu
@ -13,7 +13,7 @@ import (
"github.com/tklauser/go-sysconf"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
var ClocksPerSec = float64(100)

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
import (
@ -20,7 +21,7 @@ func TestTimesEmpty(t *testing.T) {
}
}
func TestCPUparseStatLine_424(t *testing.T) {
func TestParseStatLine_424(t *testing.T) {
t.Setenv("HOST_PROC", "testdata/linux/424/proc")
{
l, err := Times(true)
@ -38,7 +39,7 @@ func TestCPUparseStatLine_424(t *testing.T) {
}
}
func TestCPUCountsAgainstLscpu(t *testing.T) {
func TestCountsAgainstLscpu(t *testing.T) {
cmd := exec.Command("lscpu")
cmd.Env = []string{"LC_ALL=C"}
out, err := cmd.Output()
@ -93,7 +94,7 @@ func TestCPUCountsAgainstLscpu(t *testing.T) {
}
}
func TestCPUCountsLogicalAndroid_1037(t *testing.T) { // https://github.com/shirou/gopsutil/issues/1037
func TestCountsLogicalAndroid_1037(t *testing.T) { // https://github.com/shirou/gopsutil/issues/1037
t.Setenv("HOST_PROC", "testdata/linux/1037/proc")
count, err := Counts(true)

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build netbsd
// +build netbsd
package cpu
@ -9,7 +9,7 @@ import (
"runtime"
"unsafe"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
)

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build openbsd
// +build openbsd
package cpu
@ -9,7 +9,7 @@ import (
"runtime"
"unsafe"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
)

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
type cpuTimes struct {

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build plan9
// +build plan9
package cpu
@ -9,7 +9,7 @@ import (
"runtime"
stats "github.com/lufia/plan9stats"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
func Times(percpu bool) ([]TimesStat, error) {

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build plan9
// +build plan9
package cpu

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
import (

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
import (

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package cpu
import (
@ -10,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
func skipIfNotImplementedErr(t *testing.T, err error) {
@ -19,7 +20,7 @@ func skipIfNotImplementedErr(t *testing.T, err error) {
}
}
func TestCpu_times(t *testing.T) {
func TestTimes(t *testing.T) {
v, err := Times(false)
skipIfNotImplementedErr(t, err)
if err != nil {
@ -77,7 +78,7 @@ func TestCpu_times(t *testing.T) {
}
}
func TestCpu_counts(t *testing.T) {
func TestCounts(t *testing.T) {
v, err := Counts(true)
skipIfNotImplementedErr(t, err)
if err != nil {
@ -98,7 +99,7 @@ func TestCpu_counts(t *testing.T) {
t.Logf("physical cores: %d", v)
}
func TestCPUTimeStat_String(t *testing.T) {
func TestTimeStat_String(t *testing.T) {
v := TimesStat{
CPU: "cpu0",
User: 100.1,
@ -111,7 +112,7 @@ func TestCPUTimeStat_String(t *testing.T) {
}
}
func TestCpuInfo(t *testing.T) {
func TestInfo(t *testing.T) {
v, err := Info()
skipIfNotImplementedErr(t, err)
if err != nil {
@ -127,7 +128,7 @@ func TestCpuInfo(t *testing.T) {
}
}
func testCPUPercent(t *testing.T, percpu bool) {
func testPercent(t *testing.T, percpu bool) {
numcpu := runtime.NumCPU()
testCount := 3
@ -161,7 +162,7 @@ func testCPUPercent(t *testing.T, percpu bool) {
}
}
func testCPUPercentLastUsed(t *testing.T, percpu bool) {
func testPercentLastUsed(t *testing.T, percpu bool) {
numcpu := runtime.NumCPU()
testCount := 10
@ -195,18 +196,18 @@ func testCPUPercentLastUsed(t *testing.T, percpu bool) {
}
}
func TestCPUPercent(t *testing.T) {
testCPUPercent(t, false)
func TestPercent(t *testing.T) {
testPercent(t, false)
}
func TestCPUPercentPerCpu(t *testing.T) {
testCPUPercent(t, true)
func TestPercentPerCpu(t *testing.T) {
testPercent(t, true)
}
func TestCPUPercentIntervalZero(t *testing.T) {
testCPUPercentLastUsed(t, false)
func TestPercentIntervalZero(t *testing.T) {
testPercentLastUsed(t, false)
}
func TestCPUPercentIntervalZeroPerCPU(t *testing.T) {
testCPUPercentLastUsed(t, true)
func TestPercentIntervalZeroPerCPU(t *testing.T) {
testPercentLastUsed(t, true)
}

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build windows
// +build windows
package cpu
@ -8,14 +8,12 @@ import (
"fmt"
"unsafe"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/yusufpapurcu/wmi"
"golang.org/x/sys/windows"
)
var (
procGetNativeSystemInfo = common.Modkernel32.NewProc("GetNativeSystemInfo")
)
var procGetNativeSystemInfo = common.Modkernel32.NewProc("GetNativeSystemInfo")
type win32_Processor struct {
Family uint16

@ -1,10 +1,11 @@
// SPDX-License-Identifier: BSD-3-Clause
package disk
import (
"context"
"encoding/json"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
var invoke common.Invoker = common.Invoke{}

@ -1,12 +1,12 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build aix
// +build aix
package disk
import (
"context"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build aix && cgo
// +build aix,cgo
package disk

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build aix && !cgo
// +build aix,!cgo
package disk
@ -8,19 +8,21 @@ import (
"regexp"
"strings"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/unix"
)
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",
}
var (
ignoreFSType = map[string]bool{"procfs": true}
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",
}
)
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
var ret []PartitionStat

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build darwin
// +build darwin
package disk
@ -8,7 +8,7 @@ import (
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
// PartitionsWithContext returns disk partition.

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build darwin && cgo && !ios
// +build darwin,cgo,!ios
package disk
@ -14,7 +14,7 @@ import "C"
import (
"context"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {

@ -1,12 +1,12 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build (darwin && !cgo) || ios
// +build darwin,!cgo ios
package disk
import (
"context"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {

@ -1,12 +1,12 @@
//go:build !darwin && !linux && !freebsd && !openbsd && !netbsd && !windows && !solaris && !aix
// +build !darwin,!linux,!freebsd,!openbsd,!netbsd,!windows,!solaris,!aix
// SPDX-License-Identifier: BSD-3-Clause
//go:build !darwin && !linux && !freebsd && !openbsd && !netbsd && !windows && !solaris && !aix
package disk
import (
"context"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build freebsd
// +build freebsd
package disk
@ -12,7 +12,7 @@ import (
"strconv"
"strings"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/unix"
)

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_freebsd.go

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_freebsd.go

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_freebsd.go

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build freebsd && arm64
// +build freebsd,arm64
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs disk/types_freebsd.go

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build linux
// +build linux
package disk
@ -16,7 +16,7 @@ import (
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
const (

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build netbsd
// +build netbsd
package disk
@ -7,7 +7,7 @@ import (
"context"
"unsafe"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/unix"
)

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build netbsd && amd64
// +build netbsd,amd64
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs types_netbsd.go

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build netbsd && arm64
// +build netbsd,arm64
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs types_netbsd.go

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build openbsd
// +build openbsd
package disk
@ -8,7 +8,7 @@ import (
"context"
"encoding/binary"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/unix"
)

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build openbsd && 386
// +build openbsd,386
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs disk/types_openbsd.go
@ -34,5 +34,7 @@ type Timeval struct {
Usec int32
}
type Diskstat struct{}
type bintime struct{}
type (
Diskstat struct{}
bintime struct{}
)

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs types_openbsd.go
@ -32,5 +33,7 @@ type Timeval struct {
Usec int64
}
type Diskstat struct{}
type bintime struct{}
type (
Diskstat struct{}
bintime struct{}
)

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build openbsd && arm
// +build openbsd,arm
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs disk/types_openbsd.go
@ -34,5 +34,7 @@ type Timeval struct {
Usec int32
}
type Diskstat struct{}
type bintime struct{}
type (
Diskstat struct{}
bintime struct{}
)

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build openbsd && arm64
// +build openbsd,arm64
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs disk/types_openbsd.go
@ -34,5 +34,7 @@ type Timeval struct {
Usec int64
}
type Diskstat struct{}
type bintime struct{}
type (
Diskstat struct{}
bintime struct{}
)

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build openbsd && riscv64
// +build openbsd,riscv64
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs disk/types_openbsd.go
@ -36,5 +36,7 @@ type (
}
)
type Diskstat struct{}
type bintime struct{}
type (
Diskstat struct{}
bintime struct{}
)

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build solaris
// +build solaris
package disk
@ -16,7 +16,7 @@ import (
"strconv"
"strings"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/unix"
)

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package disk
import (
@ -7,7 +8,7 @@ import (
"sync"
"testing"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
func skipIfNotImplementedErr(t *testing.T, err error) {
@ -16,7 +17,7 @@ func skipIfNotImplementedErr(t *testing.T, err error) {
}
}
func TestDisk_usage(t *testing.T) {
func TestUsage(t *testing.T) {
path := "/"
if runtime.GOOS == "windows" {
path = "C:"
@ -31,7 +32,7 @@ func TestDisk_usage(t *testing.T) {
}
}
func TestDisk_partitions(t *testing.T) {
func TestPartitions(t *testing.T) {
ret, err := Partitions(false)
skipIfNotImplementedErr(t, err)
if err != nil || len(ret) == 0 {
@ -49,7 +50,7 @@ func TestDisk_partitions(t *testing.T) {
}
}
func TestDisk_io_counters(t *testing.T) {
func TestIOCounters(t *testing.T) {
ret, err := IOCounters()
skipIfNotImplementedErr(t, err)
if err != nil {
@ -68,7 +69,7 @@ func TestDisk_io_counters(t *testing.T) {
}
// https://github.com/shirou/gopsutil/issues/560 regression test
func TestDisk_io_counters_concurrency_on_darwin_cgo(t *testing.T) {
func TestIOCounters_concurrency_on_darwin_cgo(t *testing.T) {
if runtime.GOOS != "darwin" {
t.Skip("darwin only")
}
@ -84,7 +85,7 @@ func TestDisk_io_counters_concurrency_on_darwin_cgo(t *testing.T) {
wg.Wait()
}
func TestDiskUsageStat_String(t *testing.T) {
func TestUsageStat_String(t *testing.T) {
v := UsageStat{
Path: "/",
Total: 1000,
@ -103,7 +104,7 @@ func TestDiskUsageStat_String(t *testing.T) {
}
}
func TestDiskPartitionStat_String(t *testing.T) {
func TestPartitionStat_String(t *testing.T) {
v := PartitionStat{
Device: "sd01",
Mountpoint: "/",
@ -116,7 +117,7 @@ func TestDiskPartitionStat_String(t *testing.T) {
}
}
func TestDiskIOCountersStat_String(t *testing.T) {
func TestIOCountersStat_String(t *testing.T) {
v := IOCountersStat{
Name: "sd01",
ReadCount: 100,

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build freebsd || linux || darwin || (aix && !cgo)
// +build freebsd linux darwin aix,!cgo
package disk

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build windows
// +build windows
package disk
@ -10,7 +10,7 @@ import (
"syscall"
"unsafe"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
)

@ -1,3 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: Copyright (c) 2017, kadota kyohei
// https://github.com/lufia/iostat/blob/9f7362b77ad333b26c01c99de52a11bdb650ded2/iostat_darwin.c
#include <stdint.h>
#include <CoreFoundation/CoreFoundation.h>

@ -1,3 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: Copyright (c) 2017, kadota kyohei
// https://github.com/lufia/iostat/blob/9f7362b77ad333b26c01c99de52a11bdb650ded2/iostat_darwin.h
typedef struct DriveStats DriveStats;
typedef struct CPUStats CPUStats;

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build ignore
// +build ignore
// Hand writing: _Ctype_struct___0

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build ignore
// +build ignore
// Hand writing: _Ctype_struct___0

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build ignore
// +build ignore
// Hand writing: _Ctype_struct___0

@ -1 +1,2 @@
// SPDX-License-Identifier: BSD-3-Clause
package gopsutil

@ -1,11 +1,12 @@
// SPDX-License-Identifier: BSD-3-Clause
package docker
import (
"encoding/json"
"errors"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/cpu"
"github.com/shirou/gopsutil/v4/internal/common"
)
var (

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build linux
// +build linux
package docker
@ -13,8 +13,8 @@ import (
"strconv"
"strings"
cpu "github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/internal/common"
cpu "github.com/shirou/gopsutil/v4/cpu"
"github.com/shirou/gopsutil/v4/internal/common"
)
// GetDockerStat returns a list of Docker basic stats.

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build linux
// +build linux
package docker

@ -1,12 +1,12 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build !linux
// +build !linux
package docker
import (
"context"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
// GetDockerStat returns a list of Docker basic stats.

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package docker
import (

@ -1,6 +1,6 @@
module github.com/shirou/gopsutil/v3
module github.com/shirou/gopsutil/v4
go 1.15
go 1.20
require (
github.com/google/go-cmp v0.6.0
@ -13,4 +13,10 @@ require (
golang.org/x/sys v0.19.0
)
retract v3.22.11
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

@ -1,10 +1,8 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
@ -16,14 +14,6 @@ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:Om
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
@ -41,6 +31,5 @@ golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
package host
import (
@ -8,7 +9,7 @@ import (
"runtime"
"time"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
type Warnings = common.Warnings
@ -40,13 +41,6 @@ type UserStat struct {
Started int `json:"started"`
}
type TemperatureStat struct {
SensorKey string `json:"sensorKey"`
Temperature float64 `json:"temperature"`
High float64 `json:"sensorHigh"`
Critical float64 `json:"sensorCritical"`
}
func (h InfoStat) String() string {
s, _ := json.Marshal(h)
return string(s)
@ -57,11 +51,6 @@ func (u UserStat) String() string {
return string(s)
}
func (t TemperatureStat) String() string {
s, _ := json.Marshal(t)
return string(s)
}
var enableBootTimeCache bool
// EnableBootTimeCache change cache behavior of BootTime. If true, cache BootTime value. Default is false.
@ -157,10 +146,6 @@ func KernelVersion() (string, error) {
return KernelVersionWithContext(context.Background())
}
func SensorsTemperatures() ([]TemperatureStat, error) {
return SensorsTemperaturesWithContext(context.Background())
}
func timeSince(ts uint64) uint64 {
return uint64(time.Now().Unix()) - ts
}

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build darwin || freebsd || openbsd || netbsd
// +build darwin freebsd openbsd netbsd
package host

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build darwin
// +build darwin
package host
@ -15,8 +15,8 @@ import (
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v3/process"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/shirou/gopsutil/v4/process"
)
// from utmpx.h

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_darwin.go

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build darwin && arm64
// +build darwin,arm64
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs host/types_darwin.go

@ -1,14 +0,0 @@
//go:build darwin && !cgo
// +build darwin,!cgo
package host
import (
"context"
"github.com/shirou/gopsutil/v3/internal/common"
)
func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
return []TemperatureStat{}, common.ErrNotImplementedError
}

@ -1,12 +1,12 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build !darwin && !linux && !freebsd && !openbsd && !netbsd && !solaris && !windows
// +build !darwin,!linux,!freebsd,!openbsd,!netbsd,!solaris,!windows
package host
import (
"context"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
func HostIDWithContext(ctx context.Context) (string, error) {
@ -41,10 +41,6 @@ func PlatformInformationWithContext(ctx context.Context) (string, string, string
return "", "", "", common.ErrNotImplementedError
}
func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
return []TemperatureStat{}, common.ErrNotImplementedError
}
func KernelArch() (string, error) {
return "", common.ErrNotImplementedError
}

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build freebsd
// +build freebsd
package host
@ -13,8 +13,8 @@ import (
"strings"
"unsafe"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v3/process"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/shirou/gopsutil/v4/process"
"golang.org/x/sys/unix"
)
@ -141,10 +141,6 @@ func getUsersFromUtmp(utmpfile string) ([]UserStat, error) {
return ret, nil
}
func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
return []TemperatureStat{}, common.ErrNotImplementedError
}
func KernelVersionWithContext(ctx context.Context) (string, error) {
_, _, version, err := PlatformInformationWithContext(ctx)
return version, err

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs types_freebsd.go

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs types_freebsd.go

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs types_freebsd.go

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build freebsd && arm64
// +build freebsd,arm64
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs host/types_freebsd.go

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
//go:build linux
// +build linux
package host
@ -10,14 +10,12 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v4/internal/common"
)
type lsbStruct struct {
@ -30,8 +28,6 @@ type lsbStruct struct {
// from utmp.h
const (
user_PROCESS = 7
hostTemperatureScale = 1000.0
)
func HostIDWithContext(ctx context.Context) (string, error) {
@ -392,147 +388,3 @@ func getSusePlatform(contents []string) string {
func VirtualizationWithContext(ctx context.Context) (string, string, error) {
return common.VirtualizationWithContext(ctx)
}
func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
var err error
var files []string
temperatures := make([]TemperatureStat, 0)
// Only the temp*_input file provides current temperature
// value in millidegree Celsius as reported by the temperature to the device:
// https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
if files, err = filepath.Glob(common.HostSysWithContext(ctx, "/class/hwmon/hwmon*/temp*_input")); err != nil {
return temperatures, err
}
if len(files) == 0 {
// CentOS has an intermediate /device directory:
// https://github.com/giampaolo/psutil/issues/971
if files, err = filepath.Glob(common.HostSysWithContext(ctx, "/class/hwmon/hwmon*/device/temp*_input")); err != nil {
return temperatures, err
}
}
var warns Warnings
if len(files) == 0 { // handle distributions without hwmon, like raspbian #391, parse legacy thermal_zone files
files, err = filepath.Glob(common.HostSysWithContext(ctx, "/class/thermal/thermal_zone*/"))
if err != nil {
return temperatures, err
}
for _, file := range files {
// Get the name of the temperature you are reading
name, err := os.ReadFile(filepath.Join(file, "type"))
if err != nil {
warns.Add(err)
continue
}
// Get the temperature reading
current, err := os.ReadFile(filepath.Join(file, "temp"))
if err != nil {
warns.Add(err)
continue
}
temperature, err := strconv.ParseInt(strings.TrimSpace(string(current)), 10, 64)
if err != nil {
warns.Add(err)
continue
}
temperatures = append(temperatures, TemperatureStat{
SensorKey: strings.TrimSpace(string(name)),
Temperature: float64(temperature) / 1000.0,
})
}
return temperatures, warns.Reference()
}
temperatures = make([]TemperatureStat, 0, len(files))
// example directory
// device/ temp1_crit_alarm temp2_crit_alarm temp3_crit_alarm temp4_crit_alarm temp5_crit_alarm temp6_crit_alarm temp7_crit_alarm
// name temp1_input temp2_input temp3_input temp4_input temp5_input temp6_input temp7_input
// power/ temp1_label temp2_label temp3_label temp4_label temp5_label temp6_label temp7_label
// subsystem/ temp1_max temp2_max temp3_max temp4_max temp5_max temp6_max temp7_max
// temp1_crit temp2_crit temp3_crit temp4_crit temp5_crit temp6_crit temp7_crit uevent
for _, file := range files {
var raw []byte
var temperature float64
// Get the base directory location
directory := filepath.Dir(file)
// Get the base filename prefix like temp1
basename := strings.Split(filepath.Base(file), "_")[0]
// Get the base path like <dir>/temp1
basepath := filepath.Join(directory, basename)
// Get the label of the temperature you are reading
label := ""
if raw, _ = os.ReadFile(basepath + "_label"); len(raw) != 0 {
// Format the label from "Core 0" to "core_0"
label = strings.Join(strings.Split(strings.TrimSpace(strings.ToLower(string(raw))), " "), "_")
}
// Get the name of the temperature you are reading
if raw, err = os.ReadFile(filepath.Join(directory, "name")); err != nil {
warns.Add(err)
continue
}
name := strings.TrimSpace(string(raw))
if label != "" {
name = name + "_" + label
}
// Get the temperature reading
if raw, err = os.ReadFile(file); err != nil {
warns.Add(err)
continue
}
if temperature, err = strconv.ParseFloat(strings.TrimSpace(string(raw)), 64); err != nil {
warns.Add(err)
continue
}
// Add discovered temperature sensor to the list
temperatures = append(temperatures, TemperatureStat{
SensorKey: name,
Temperature: temperature / hostTemperatureScale,
High: optionalValueReadFromFile(basepath+"_max") / hostTemperatureScale,
Critical: optionalValueReadFromFile(basepath+"_crit") / hostTemperatureScale,
})
}
return temperatures, warns.Reference()
}
func optionalValueReadFromFile(filename string) float64 {
var raw []byte
var err error
var value float64
// Check if file exists
if _, err := os.Stat(filename); os.IsNotExist(err) {
return 0
}
if raw, err = os.ReadFile(filename); err != nil {
return 0
}
if value, err = strconv.ParseFloat(strings.TrimSpace(string(raw)), 64); err != nil {
return 0
}
return value
}

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// ATTENTION - FILE MANUAL FIXED AFTER CGO.
// Fixed line: Tv _Ctype_struct_timeval -> Tv UtTv
// Created by cgo -godefs, MANUAL FIXED

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_linux.go

@ -1,3 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_linux.go | sed "s/uint8/int8/g"

@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs types_linux.go
package host

@ -1,8 +1,8 @@
// SPDX-License-Identifier: BSD-3-Clause
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs host/types_linux.go
//go:build linux && loong64
// +build linux,loong64
package host

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save