Skip to content

Commit

Permalink
Merge remote-tracking branch 'downstream/master' into elfrucool/fix-w…
Browse files Browse the repository at this point in the history
…indows-load-avg
elfrucool committed Feb 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents e45e817 + e767a0f commit e787f1a
Showing 69 changed files with 1,271 additions and 194 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -22,17 +22,17 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Install Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- id: cache-paths
run: |
echo "::set-output name=cache::$(go env GOCACHE)"
echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
- name: Cache go modules
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
with:
path: |
${{ steps.cache-paths.outputs.cache }}
7 changes: 4 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -16,13 +16,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Setup go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: 1.17
cache: false
- name: Checkout repository
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.0
with:
args: --verbose
version: latest
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -10,6 +10,6 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Release
run: make release
4 changes: 2 additions & 2 deletions .github/workflows/sbom_generator.yml
Original file line number Diff line number Diff line change
@@ -13,13 +13,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- uses: advanced-security/sbom-generator-action@375dee8e6144d9fd0ec1f5667b4f6fb4faacefed # v0.0.1
id: sbom
env:
GITHUB_TOKEN: ${{ github.token }}
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
path: ${{steps.sbom.outputs.fileName }}
name: "SBOM"
2 changes: 1 addition & 1 deletion .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -8,6 +8,6 @@ jobs:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 # v2.0.0
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -19,21 +19,21 @@ jobs:
fail-fast: false
matrix:
go-version: ${{fromJson(needs.go-versions.outputs.versions)}}
os: [ubuntu-22.04, ubuntu-20.04, windows-2022, windows-2019, macos-11, macos-12]
os: [ubuntu-22.04, ubuntu-20.04, windows-2022, windows-2019, macos-11, macos-12, macos-13, macos-14]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- id: go-env
run: |
echo "::set-output name=cache::$(go env GOCACHE)"
echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
- name: Cache go modules
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
with:
path: |
${{ steps.go-env.outputs.cache }}
47 changes: 27 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
issues:
max-same-issues: 0
exclude-rules:
- linters:
- gosec
text: "G204"
- linters:
- revive
text: "var-naming"
- linters:
- revive
text: "exported"
- linters:
- revive
text: "empty-block"
- linters:
- revive
text: "unused-parameter"
exclude-rules:
- linters:
- gosec
text: "G204"
- linters:
- revive
text: "var-naming"
- linters:
- revive
text: "exported"
- linters:
- revive
text: "empty-block"
- linters:
- revive
text: "unused-parameter"
linters:
enable:
- asciicheck
@@ -26,6 +26,7 @@ linters:
- gofmt
- gofumpt
- goimports
- gomodguard
- gosec
- gosimple
- importas
@@ -46,10 +47,16 @@ linters:
- structcheck
- unused
- varcheck

linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/shirou)
- standard
- default
- prefix(github.com/shirou)
gomodguard:
blocked:
modules:
- io/ioutil:
recommandations:
- io
- os
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ build_test: ## test only buildable
GOOS=linux GOARCH=loong64 go test ./... | $(BUILD_FAIL_PATTERN)
GOOS=linux GOARCH=riscv64 go test ./... | $(BUILD_FAIL_PATTERN)
GOOS=linux GOARCH=s390x go test ./... | $(BUILD_FAIL_PATTERN)
GOOS=linux GOARCH=mips go test ./... | $(BUILD_FAIL_PATTERN)
GOOS=freebsd GOARCH=amd64 go test ./... | $(BUILD_FAIL_PATTERN)
GOOS=freebsd GOARCH=386 go test ./... | $(BUILD_FAIL_PATTERN)
GOOS=freebsd GOARCH=arm go test ./... | $(BUILD_FAIL_PATTERN)
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ can be skipped.
- Linux i386/amd64/arm(raspberry pi)
- Windows i386/amd64/arm/arm64
- Darwin amd64/arm64
- OpenBSD amd64 (Thank you @mpfz0r!)
- OpenBSD i386/amd64/armv7/arm64/riscv64 (Thank you @mpfz0r!)
- Solaris amd64 (developed and tested on SmartOS/Illumos, Thank you
@jen20!)

@@ -109,6 +109,17 @@ As of v3.23.6, it is now possible to pass a path location using `context`: impor

First priority is given to the value set in `context`, then the value from the environment variable, and finally the default location.

### Caching

As of v3.24.1, it is now possible to cached some values. These values default to false, not cached.

Be very careful that enabling the cache may cause inconsistencies. For example, if you enable caching of boottime on Linux, be aware that unintended values may be returned if [the boottime is changed by NTP after booted](https://github.com/shirou/gopsutil/issues/1070#issuecomment-842512782).

- `host`
- EnableBootTimeCache
- `process`
- EnableBootTimeCache

## Documentation

See https://pkg.go.dev/github.com/shirou/gopsutil/v3 or https://godocs.io/github.com/shirou/gopsutil/v3
@@ -190,7 +201,7 @@ Some code is ported from Ohai. Many thanks.
|users |x |x |x |x |x | | |
|pids |x |x |x |x |x | | |
|pid\_exists |x |x |x |x |x | | |
|net\_connections |x | |x |x | | | |
|net\_connections |x |x |x |x | | | |
|net\_protocols |x | | | | | | |
|net\_if\_addrs | | | | | | | |
|net\_if\_stats | | | | | | | |
@@ -207,7 +218,7 @@ Some code is ported from Ohai. Many thanks.
|cmdline |x |x | |x |x |
|create\_time |x | | |x |x |
|status |x |x |x |x | |
|cwd |x | | |x | |
|cwd |x | | |x |x |
|exe |x |x |x | |x |
|uids |x |x |x |x | |
|gids |x |x |x |x | |
11 changes: 4 additions & 7 deletions cpu/cpu_aix_nocgo.go
Original file line number Diff line number Diff line change
@@ -5,15 +5,12 @@ package cpu

import (
"context"
"regexp"
"strconv"
"strings"

"github.com/shirou/gopsutil/v3/internal/common"
)

var whiteSpaces = regexp.MustCompile(`\s+`)

func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
if percpu {
return []TimesStat{}, common.ErrNotImplementedError
@@ -28,8 +25,8 @@ 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 := strings.Fields(lines[len(lines)-3]) // headers
v := strings.Fields(lines[len(lines)-2]) // values
for i, header := range h {
if t, err := strconv.ParseFloat(v[i], 64); err == nil {
switch header {
@@ -58,14 +55,14 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
ret := InfoStat{}
for _, line := range strings.Split(string(out), "\n") {
if strings.HasPrefix(line, "Number Of Processors:") {
p := whiteSpaces.Split(line, 4)
p := strings.Fields(line)
if len(p) > 3 {
if t, err := strconv.ParseUint(p[3], 10, 64); err == nil {
ret.Cores = int32(t)
}
}
} else if strings.HasPrefix(line, "Processor Clock Speed:") {
p := whiteSpaces.Split(line, 5)
p := strings.Fields(line)
if len(p) > 4 {
if t, err := strconv.ParseFloat(p[3], 64); err == nil {
switch strings.ToUpper(p[4]) {
3 changes: 2 additions & 1 deletion cpu/cpu_darwin_test.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
package cpu

import (
"os"
"testing"

"github.com/shoenig/go-m1cpu"
@@ -23,7 +24,7 @@ func Test_CpuInfo_AppleSilicon(t *testing.T) {
if vv.ModelName == "" {
t.Errorf("could not get CPU info: %v", vv)
}
if vv.Mhz <= 0 {
if vv.Mhz <= 0 && os.Getenv("CI") != "true" {
t.Errorf("could not get frequency of: %s", vv.ModelName)
}
if vv.Mhz > 6000 {
4 changes: 2 additions & 2 deletions cpu/cpu_fallback.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows && !dragonfly && !plan9 && !aix
// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!dragonfly,!plan9,!aix
//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

2 changes: 1 addition & 1 deletion cpu/cpu_linux.go
Original file line number Diff line number Diff line change
@@ -309,7 +309,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
func parseStatLine(line string) (*TimesStat, error) {
fields := strings.Fields(line)

if len(fields) == 0 {
if len(fields) < 8 {
return nil, errors.New("stat does not contain cpu info")
}

Loading

0 comments on commit e787f1a

Please sign in to comment.