MSP-8976 Up deps
This commit is contained in:
1 parent
b8ef777339
commit
11d705124d
603 files changed
+47715
-13202
No files matched your search
+12
-9
@@ -6,6 +6,8 @@ linters:
|
||||
- gocritic
|
||||
- godot
|
||||
- misspell
|
||||
- modernize
|
||||
- perfsprint
|
||||
- revive
|
||||
- testifylint
|
||||
settings:
|
||||
@@ -34,14 +36,6 @@ linters:
|
||||
capital: true
|
||||
misspell:
|
||||
locale: US
|
||||
revive:
|
||||
rules:
|
||||
- name: var-naming
|
||||
# TODO(SuperQ): See: https://github.com/prometheus/prometheus/issues/17766
|
||||
arguments:
|
||||
- []
|
||||
- []
|
||||
- - skip-package-name-checks: true
|
||||
exclusions:
|
||||
presets:
|
||||
- comments
|
||||
@@ -51,9 +45,18 @@ linters:
|
||||
warn-unused: true
|
||||
formatters:
|
||||
enable:
|
||||
- gofmt
|
||||
- gci
|
||||
- gofumpt
|
||||
- goimports
|
||||
settings:
|
||||
gci:
|
||||
sections:
|
||||
- standard
|
||||
- default
|
||||
- prefix(github.com/prometheus/procfs)
|
||||
gofumpt:
|
||||
extra:
|
||||
group-params: true
|
||||
goimports:
|
||||
local-prefixes:
|
||||
- github.com/prometheus/procfs
|
||||
+4
-4
@@ -96,7 +96,7 @@ The `proc` and `sys` filesystems are pseudo file systems and work a bit differen
|
||||
Many of the files are changing continuously and the data being read can in some cases change between subsequent
|
||||
reads in the same file. Also, most of the files are relatively small (less than a few KBs), and system calls
|
||||
to the `stat` function will often return the wrong size. Therefore, for most files it's recommended to read the
|
||||
full file in a single operation using an internal utility function called `util.ReadFileNoStat`.
|
||||
full file in a single operation using an internal utility function called `parsers.ReadFileNoStat`.
|
||||
This function is similar to `os.ReadFile`, but it avoids the system call to `stat` to get the current size of
|
||||
the file.
|
||||
|
||||
@@ -104,7 +104,7 @@ Note that parsing the file's contents can still be performed one line at a time.
|
||||
the full file, and then using a scanner on the `[]byte` or `string` containing the data.
|
||||
|
||||
```
|
||||
data, err := util.ReadFileNoStat("/proc/cpuinfo")
|
||||
data, err := parsers.ReadFileNoStat("/proc/cpuinfo")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -113,9 +113,9 @@ the full file, and then using a scanner on the `[]byte` or `string` containing t
|
||||
```
|
||||
|
||||
The `/sys` filesystem contains many very small files which contain only a single numeric or text value. These files
|
||||
can be read using an internal function called `util.SysReadFile` which is similar to `os.ReadFile` but does
|
||||
can be read using an internal function called `parsers.SysReadFile` which is similar to `os.ReadFile` but does
|
||||
not bother to check the size of the file before reading.
|
||||
```
|
||||
data, err := util.SysReadFile("/sys/class/power_supply/BAT0/capacity")
|
||||
data, err := parsers.SysReadFile("/sys/class/power_supply/BAT0/capacity")
|
||||
```
|
||||
|
||||
+16
-2
@@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
|
||||
SKIP_GOLANGCI_LINT :=
|
||||
GOLANGCI_LINT :=
|
||||
GOLANGCI_LINT_OPTS ?=
|
||||
GOLANGCI_LINT_VERSION ?= v2.11.4
|
||||
GOLANGCI_LINT_VERSION ?= v2.14.0
|
||||
GOLANGCI_FMT_OPTS ?=
|
||||
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
|
||||
# windows isn't included here because of the path separator being different.
|
||||
@@ -165,8 +165,9 @@ common-deps:
|
||||
.PHONY: update-go-deps
|
||||
update-go-deps:
|
||||
@echo ">> updating Go dependencies"
|
||||
# GOTOOLCHAIN prevents go get from pulling deps that require a newer Go version.
|
||||
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
|
||||
$(GO) get $$m; \
|
||||
GOTOOLCHAIN=go$$($(GO) mod edit -json | jq -r .Go) $(GO) get $$m; \
|
||||
done
|
||||
$(GO) mod tidy
|
||||
|
||||
@@ -246,6 +247,12 @@ common-docker-repo-name:
|
||||
|
||||
.PHONY: common-docker $(BUILD_DOCKER_ARCHS)
|
||||
common-docker: $(BUILD_DOCKER_ARCHS)
|
||||
|
||||
.PHONY: common-docker-current-arch
|
||||
common-docker-current-arch:
|
||||
$(MAKE) common-docker-$(GOHOSTARCH)
|
||||
|
||||
# DOCKER_ARCHS holds promu architecture names, which are not OCI platform strings.
|
||||
$(BUILD_DOCKER_ARCHS): common-docker-%:
|
||||
@for variant in $(DOCKERFILE_VARIANTS_WITH_NAMES); do \
|
||||
dockerfile=$${variant#*:}; \
|
||||
@@ -254,10 +261,16 @@ $(BUILD_DOCKER_ARCHS): common-docker-%:
|
||||
if [ "$*" = "armv7" ]; then \
|
||||
distroless_arch="arm"; \
|
||||
fi; \
|
||||
arch="$*"; \
|
||||
case "$$arch" in \
|
||||
armv*) docker_platform="linux/arm/v$${arch#armv}";; \
|
||||
*) docker_platform="linux/$$arch";; \
|
||||
esac; \
|
||||
if [ "$$dockerfile" = "Dockerfile" ]; then \
|
||||
echo "Building default variant ($$variant_name) for linux-$* using $$dockerfile"; \
|
||||
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" \
|
||||
-f $$dockerfile \
|
||||
--platform "$$docker_platform" \
|
||||
--build-arg ARCH="$*" \
|
||||
--build-arg OS="linux" \
|
||||
--build-arg DISTROLESS_ARCH="$$distroless_arch" \
|
||||
@@ -271,6 +284,7 @@ $(BUILD_DOCKER_ARCHS): common-docker-%:
|
||||
echo "Building $$variant_name variant for linux-$* using $$dockerfile"; \
|
||||
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)-$$variant_name" \
|
||||
-f $$dockerfile \
|
||||
--platform "$$docker_platform" \
|
||||
--build-arg ARCH="$*" \
|
||||
--build-arg OS="linux" \
|
||||
--build-arg DISTROLESS_ARCH="$$distroless_arch" \
|
||||
|
||||
+2
-2
@@ -16,12 +16,12 @@ package procfs
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// CmdLine returns the command line of the kernel.
|
||||
func (fs FS) CmdLine() ([]string, error) {
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path("cmdline"))
|
||||
data, err := parsers.ReadFileNoStat(fs.proc.Path("cmdline"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+90
-8
@@ -24,7 +24,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// CPUInfo contains general information about a system CPU found in /proc/cpuinfo.
|
||||
@@ -65,7 +65,7 @@ var (
|
||||
// CPUInfo returns information about current system CPUs.
|
||||
// See https://www.kernel.org/doc/Documentation/filesystems/proc.txt
|
||||
func (fs FS) CPUInfo() ([]CPUInfo, error) {
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path("cpuinfo"))
|
||||
data, err := parsers.ReadFileNoStat(fs.proc.Path("cpuinfo"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -187,6 +187,24 @@ func parseCPUInfoX86(info []byte) ([]CPUInfo, error) {
|
||||
return cpuinfo, nil
|
||||
}
|
||||
|
||||
func formatSteppingARM(variant, revision string) string {
|
||||
if variant == "" && revision == "" {
|
||||
return ""
|
||||
}
|
||||
varNum, errV := strconv.ParseUint(variant, 0, 64)
|
||||
revNum, errR := strconv.ParseUint(revision, 0, 64)
|
||||
if errV == nil && errR == nil {
|
||||
return fmt.Sprintf("r%dp%d", varNum, revNum)
|
||||
}
|
||||
if errV == nil {
|
||||
return fmt.Sprintf("r%d", varNum)
|
||||
}
|
||||
if errR == nil {
|
||||
return fmt.Sprintf("p%d", revNum)
|
||||
}
|
||||
return fmt.Sprintf("r%sp%s", variant, revision)
|
||||
}
|
||||
|
||||
func parseCPUInfoARM(info []byte) ([]CPUInfo, error) {
|
||||
scanner := bufio.NewScanner(bytes.NewReader(info))
|
||||
|
||||
@@ -194,12 +212,13 @@ func parseCPUInfoARM(info []byte) ([]CPUInfo, error) {
|
||||
match, err := regexp.MatchString("^[Pp]rocessor", firstLine)
|
||||
if !match || !strings.Contains(firstLine, ":") {
|
||||
return nil, fmt.Errorf("%w: Cannot parse line: %q: %w", ErrFileParse, firstLine, err)
|
||||
|
||||
}
|
||||
field := strings.SplitN(firstLine, ": ", 2)
|
||||
cpuinfo := []CPUInfo{}
|
||||
featuresLine := ""
|
||||
commonCPUInfo := CPUInfo{}
|
||||
variants := make(map[int]string)
|
||||
revisions := make(map[int]string)
|
||||
i := 0
|
||||
if strings.TrimSpace(field[0]) == "Processor" {
|
||||
commonCPUInfo = CPUInfo{ModelName: field[1]}
|
||||
@@ -219,6 +238,9 @@ func parseCPUInfoARM(info []byte) ([]CPUInfo, error) {
|
||||
continue
|
||||
}
|
||||
field := strings.SplitN(line, ": ", 2)
|
||||
if len(field) < 2 {
|
||||
continue
|
||||
}
|
||||
switch strings.TrimSpace(field[0]) {
|
||||
case "processor":
|
||||
cpuinfo = append(cpuinfo, commonCPUInfo) // start of the next processor
|
||||
@@ -242,15 +264,75 @@ func parseCPUInfoARM(info []byte) ([]CPUInfo, error) {
|
||||
case "Features":
|
||||
featuresLine = line
|
||||
case "model name":
|
||||
cpuinfo[i].ModelName = field[1]
|
||||
if i == -1 {
|
||||
commonCPUInfo.ModelName = field[1]
|
||||
} else {
|
||||
cpuinfo[i].ModelName = field[1]
|
||||
}
|
||||
case "CPU implementer", "cpu implementer":
|
||||
val := strings.TrimSpace(field[1])
|
||||
if i == -1 {
|
||||
commonCPUInfo.VendorID = val
|
||||
} else {
|
||||
cpuinfo[i].VendorID = val
|
||||
}
|
||||
case "CPU architecture", "cpu architecture":
|
||||
val := strings.TrimSpace(field[1])
|
||||
if i == -1 {
|
||||
commonCPUInfo.CPUFamily = val
|
||||
} else {
|
||||
cpuinfo[i].CPUFamily = val
|
||||
}
|
||||
case "CPU part", "cpu part":
|
||||
val := strings.TrimSpace(field[1])
|
||||
if i == -1 {
|
||||
commonCPUInfo.Model = val
|
||||
} else {
|
||||
cpuinfo[i].Model = val
|
||||
}
|
||||
case "CPU variant", "cpu variant":
|
||||
variants[i] = strings.TrimSpace(field[1])
|
||||
case "CPU revision", "cpu revision":
|
||||
revisions[i] = strings.TrimSpace(field[1])
|
||||
}
|
||||
}
|
||||
fields := strings.SplitN(featuresLine, ": ", 2)
|
||||
for i := range cpuinfo {
|
||||
cpuinfo[i].Flags = strings.Fields(fields[1])
|
||||
|
||||
for j := range cpuinfo {
|
||||
stepping := formatSteppingARM(variants[j], revisions[j])
|
||||
if stepping == "" {
|
||||
stepping = formatSteppingARM(variants[-1], revisions[-1])
|
||||
}
|
||||
cpuinfo[j].Stepping = stepping
|
||||
}
|
||||
|
||||
if len(cpuinfo) > 0 && cpuinfo[0].VendorID == "" && cpuinfo[len(cpuinfo)-1].VendorID != "" {
|
||||
last := cpuinfo[len(cpuinfo)-1]
|
||||
for j := range cpuinfo {
|
||||
if cpuinfo[j].VendorID == "" {
|
||||
cpuinfo[j].VendorID = last.VendorID
|
||||
}
|
||||
if cpuinfo[j].CPUFamily == "" {
|
||||
cpuinfo[j].CPUFamily = last.CPUFamily
|
||||
}
|
||||
if cpuinfo[j].Model == "" {
|
||||
cpuinfo[j].Model = last.Model
|
||||
}
|
||||
if cpuinfo[j].Stepping == "" {
|
||||
cpuinfo[j].Stepping = last.Stepping
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if featuresLine != "" {
|
||||
fields := strings.SplitN(featuresLine, ": ", 2)
|
||||
if len(fields) > 1 {
|
||||
flags := strings.Fields(fields[1])
|
||||
for i := range cpuinfo {
|
||||
cpuinfo[i].Flags = flags
|
||||
}
|
||||
}
|
||||
}
|
||||
return cpuinfo, nil
|
||||
|
||||
}
|
||||
|
||||
func parseCPUInfoS390X(info []byte) ([]CPUInfo, error) {
|
||||
|
||||
+3
-4
@@ -20,7 +20,7 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Crypto holds info parsed from /proc/crypto.
|
||||
@@ -55,10 +55,9 @@ var cryptoFile = "crypto"
|
||||
// https://kernel.readthedocs.io/en/sphinx-samples/crypto-API.html
|
||||
func (fs FS) Crypto() ([]Crypto, error) {
|
||||
path := fs.proc.Path(cryptoFile)
|
||||
b, err := util.ReadFileNoStat(path)
|
||||
b, err := parsers.ReadFileNoStat(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: Cannot read file %v: %w", ErrFileRead, b, err)
|
||||
|
||||
}
|
||||
|
||||
crypto, err := parseCrypto(bytes.NewReader(b))
|
||||
@@ -112,7 +111,7 @@ func parseCrypto(r io.Reader) ([]Crypto, error) {
|
||||
|
||||
// parseKV parses a key/value pair into the appropriate field of c.
|
||||
func (c *Crypto) parseKV(k, v string) error {
|
||||
vp := util.NewValueParser(v)
|
||||
vp := parsers.NewValueParser(v)
|
||||
|
||||
switch k {
|
||||
case "async":
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@
|
||||
|
||||
package procfs
|
||||
|
||||
// isRealProc returns true on architectures that don't have a Type argument
|
||||
// isRealProc returns false on architectures that don't have a Type argument
|
||||
// in their Statfs_t struct.
|
||||
func isRealProc(_ string) (bool, error) {
|
||||
return true, nil
|
||||
return false, nil
|
||||
}
|
||||
+2
-2
@@ -21,7 +21,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Fscacheinfo represents fscache statistics.
|
||||
@@ -229,7 +229,7 @@ type Fscacheinfo struct {
|
||||
// Fscacheinfo returns information about current fscache statistics.
|
||||
// See https://www.kernel.org/doc/Documentation/filesystems/caching/fscache.txt
|
||||
func (fs FS) Fscacheinfo() (Fscacheinfo, error) {
|
||||
b, err := util.ReadFileNoStat(fs.proc.Path("fs/fscache/stats"))
|
||||
b, err := parsers.ReadFileNoStat(fs.proc.Path("fs/fscache/stats"))
|
||||
if err != nil {
|
||||
return Fscacheinfo{}, err
|
||||
}
|
||||
|
||||
+3
@@ -31,6 +31,9 @@ const (
|
||||
|
||||
// DefaultSelinuxMountPoint is the common mount point of the selinuxfs.
|
||||
DefaultSelinuxMountPoint = "/sys/fs/selinux"
|
||||
|
||||
// DefaultResctrlMountPoint is the common mount point of the resctrl filesystem.
|
||||
DefaultResctrlMountPoint = "/sys/fs/resctrl"
|
||||
)
|
||||
|
||||
// FS represents a pseudo-filesystem, normally /proc or /sys, which provides an
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -11,7 +11,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package util
|
||||
package parsers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
Generated
Vendored
+1
-1
@@ -11,7 +11,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package util
|
||||
package parsers
|
||||
|
||||
import (
|
||||
"io"
|
||||
Generated
Vendored
+1
-1
@@ -13,7 +13,7 @@
|
||||
|
||||
//go:build (linux || darwin) && !appengine
|
||||
|
||||
package util
|
||||
package parsers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
Generated
Vendored
+1
-1
@@ -13,7 +13,7 @@
|
||||
|
||||
//go:build (linux && appengine) || (!linux && !darwin)
|
||||
|
||||
package util
|
||||
package parsers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
Generated
Vendored
+1
-1
@@ -11,7 +11,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package util
|
||||
package parsers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
+5
-2
@@ -25,7 +25,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// IPVSStats holds IPVS statistics, as exposed by the kernel in `/proc/net/ip_vs_stats`.
|
||||
@@ -66,7 +66,7 @@ type IPVSBackendStatus struct {
|
||||
|
||||
// IPVSStats reads the IPVS statistics from the specified `proc` filesystem.
|
||||
func (fs FS) IPVSStats() (IPVSStats, error) {
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path("net/ip_vs_stats"))
|
||||
data, err := parsers.ReadFileNoStat(fs.proc.Path("net/ip_vs_stats"))
|
||||
if err != nil {
|
||||
return IPVSStats{}, err
|
||||
}
|
||||
@@ -149,6 +149,9 @@ func parseIPVSBackendStatus(file io.Reader) ([]IPVSBackendStatus, error) {
|
||||
if len(fields) == 0 {
|
||||
continue
|
||||
}
|
||||
if len(fields) < 2 {
|
||||
return nil, fmt.Errorf("%w: Malformed line %q", ErrFileParse, scanner.Text())
|
||||
}
|
||||
switch {
|
||||
case fields[0] == "IP" || fields[0] == "Prot" || fields[1] == "RemoteAddress:Port":
|
||||
continue
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ package procfs
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// KernelRandom contains information about to the kernel's random number generator.
|
||||
@@ -48,7 +48,7 @@ func (fs FS) KernelRandom() (KernelRandom, error) {
|
||||
"write_wakeup_threshold": &random.WriteWakeupThreshold,
|
||||
"read_wakeup_threshold": &random.ReadWakeupThreshold,
|
||||
} {
|
||||
val, err := util.ReadUintFromFile(fs.proc.Path("sys", "kernel", "random", file))
|
||||
val, err := parsers.ReadUintFromFile(fs.proc.Path("sys", "kernel", "random", file))
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build linux
|
||||
|
||||
package procfs
|
||||
|
||||
import (
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// KernelTaintBit represents a single kernel taint flag.
|
||||
type KernelTaintBit struct {
|
||||
// Index is the zero-based bit position in the tainted bitmask.
|
||||
Index int
|
||||
// Flag is the letter code identifying this taint (e.g. "L" for soft lockup).
|
||||
// See https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html
|
||||
Flag string
|
||||
// Description is a human-readable explanation of what this taint means.
|
||||
Description string
|
||||
// Set indicates whether this taint flag is currently active.
|
||||
Set bool
|
||||
}
|
||||
|
||||
// KernelTainted holds the kernel taint state read from /proc/sys/kernel/tainted.
|
||||
type KernelTainted struct {
|
||||
// Value is the raw integer from /proc/sys/kernel/tainted.
|
||||
Value uint64
|
||||
// Bits contains each known taint flag and whether it is currently set.
|
||||
// Flags are listed in bit-position order (bit 0 first).
|
||||
Bits []KernelTaintBit
|
||||
}
|
||||
|
||||
// kernelTaintBitDefs lists all known kernel taint flags in bit-position order.
|
||||
// Reference: https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html
|
||||
var kernelTaintBitDefs = []struct {
|
||||
flag string
|
||||
description string
|
||||
}{
|
||||
{"P", "Proprietary module was loaded."},
|
||||
{"F", "Module was force loaded."},
|
||||
{"S", "SMP kernel oops on an officially SMP incapable processor."},
|
||||
{"R", "Module was force unloaded."},
|
||||
{"M", "Processor reported a Machine Check Exception (MCE)."},
|
||||
{"B", "Bad page referenced or some unexpected page flags."},
|
||||
{"U", "Taint requested by userspace application."},
|
||||
{"D", "Kernel died recently, i.e. there was an OOPS or BUG."},
|
||||
{"A", "An ACPI table was overridden by user."},
|
||||
{"W", "Kernel issued warning."},
|
||||
{"C", "Staging driver was loaded."},
|
||||
{"I", "Workaround for bug in platform firmware applied."},
|
||||
{"O", "Externally-built (out-of-tree) module was loaded."},
|
||||
{"E", "Unsigned module was loaded."},
|
||||
{"L", "Soft lockup occurred."},
|
||||
{"K", "Kernel has been live patched."},
|
||||
{"X", "Auxiliary taint, defined and used by distros."},
|
||||
{"T", "The kernel was built with the struct randomization plugin."},
|
||||
{"N", "An in-kernel test such as a KUnit test has been run."},
|
||||
{"J", "Userspace used a mutating debug operation in fwctl."},
|
||||
}
|
||||
|
||||
// KernelTainted reads /proc/sys/kernel/tainted and returns the raw taint value
|
||||
// along with each known flag parsed into a KernelTainted struct.
|
||||
// See https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html
|
||||
func (fs FS) KernelTainted() (KernelTainted, error) {
|
||||
value, err := parsers.SysReadUintFromFile(fs.proc.Path("sys", "kernel", "tainted"))
|
||||
if err != nil {
|
||||
return KernelTainted{}, err
|
||||
}
|
||||
return parseTainted(value), nil
|
||||
}
|
||||
|
||||
// parseTainted builds a KernelTainted from the raw taint bitmask value.
|
||||
func parseTainted(value uint64) KernelTainted {
|
||||
bits := make([]KernelTaintBit, len(kernelTaintBitDefs))
|
||||
for i, def := range kernelTaintBitDefs {
|
||||
bits[i] = KernelTaintBit{
|
||||
Index: i,
|
||||
Flag: def.flag,
|
||||
Description: def.description,
|
||||
Set: value&(1<<uint(i)) != 0,
|
||||
}
|
||||
}
|
||||
return KernelTainted{Value: value, Bits: bits}
|
||||
}
|
||||
+2
-2
@@ -18,7 +18,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// LoadAvg represents an entry in /proc/loadavg.
|
||||
@@ -32,7 +32,7 @@ type LoadAvg struct {
|
||||
func (fs FS) LoadAvg() (*LoadAvg, error) {
|
||||
path := fs.proc.Path("loadavg")
|
||||
|
||||
data, err := util.ReadFileNoStat(path)
|
||||
data, err := parsers.ReadFileNoStat(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+3
-5
@@ -27,7 +27,7 @@ var (
|
||||
recoveryLinePctRE = regexp.MustCompile(`= (.+)%`)
|
||||
recoveryLineFinishRE = regexp.MustCompile(`finish=(.+)min`)
|
||||
recoveryLineSpeedRE = regexp.MustCompile(`speed=(.+)[A-Z]`)
|
||||
componentDeviceRE = regexp.MustCompile(`(.*)\[(\d+)\](\([SF]+\))?`)
|
||||
componentDeviceRE = regexp.MustCompile(`(.*)\[(\d+)\]((?:\([FJRSW]\))+)?`)
|
||||
personalitiesPrefix = "Personalities : "
|
||||
)
|
||||
|
||||
@@ -114,8 +114,7 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
|
||||
}
|
||||
// Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
|
||||
if len(knownRaidTypes) == 0 && strings.HasPrefix(line, personalitiesPrefix) {
|
||||
personalities := strings.Fields(line[len(personalitiesPrefix):])
|
||||
for _, word := range personalities {
|
||||
for word := range strings.FieldsSeq(line[len(personalitiesPrefix):]) {
|
||||
word := word[1 : len(word)-1]
|
||||
knownRaidTypes[word] = true
|
||||
}
|
||||
@@ -150,7 +149,6 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
|
||||
fail := int64(strings.Count(line, "(F)"))
|
||||
spare := int64(strings.Count(line, "(S)"))
|
||||
active, total, down, size, err := evalStatusLine(lines[i], lines[i+1])
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: Cannot parse md device lines: %v: %w", ErrFileParse, active, err)
|
||||
}
|
||||
@@ -275,7 +273,7 @@ func evalStatusLine(deviceLine, statusLine string) (active, total, down, size in
|
||||
return active, total, down, size, nil
|
||||
}
|
||||
|
||||
func evalRecoveryLine(recoveryLine string) (blocksSynced int64, blocksToBeSynced int64, pct float64, finish float64, speed float64, err error) {
|
||||
func evalRecoveryLine(recoveryLine string) (blocksSynced, blocksToBeSynced int64, pct, finish, speed float64, err error) {
|
||||
matches := recoveryLineBlocksRE.FindStringSubmatch(recoveryLine)
|
||||
if len(matches) != 2 {
|
||||
return 0, 0, 0, 0, 0, fmt.Errorf("%w: Unexpected recoveryLine blocks %s: %w", ErrFileParse, recoveryLine, err)
|
||||
|
||||
+5
-2
@@ -21,7 +21,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Meminfo represents memory statistics.
|
||||
@@ -210,7 +210,7 @@ type Meminfo struct {
|
||||
// Meminfo returns an information about current kernel/system memory statistics.
|
||||
// See https://www.kernel.org/doc/Documentation/filesystems/proc.txt
|
||||
func (fs FS) Meminfo() (Meminfo, error) {
|
||||
b, err := util.ReadFileNoStat(fs.proc.Path("meminfo"))
|
||||
b, err := parsers.ReadFileNoStat(fs.proc.Path("meminfo"))
|
||||
if err != nil {
|
||||
return Meminfo{}, err
|
||||
}
|
||||
@@ -228,6 +228,9 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) {
|
||||
s := bufio.NewScanner(r)
|
||||
for s.Scan() {
|
||||
fields := strings.Fields(s.Text())
|
||||
if len(fields) < 2 || len(fields) > 3 {
|
||||
return nil, fmt.Errorf("%w: Malformed line %q", ErrFileParse, s.Text())
|
||||
}
|
||||
var val, valBytes uint64
|
||||
|
||||
val, err := strconv.ParseUint(fields[1], 0, 64)
|
||||
|
||||
+27
-20
@@ -72,17 +72,18 @@ func parseMountInfo(info []byte) ([]*MountInfo, error) {
|
||||
// Parses a mountinfo file line, and converts it to a MountInfo struct.
|
||||
// An important check here is to see if the hyphen separator, as if it does not exist,
|
||||
// it means that the line is malformed.
|
||||
// See: https://man7.org/linux/man-pages/man5/proc_pid_mountinfo.5.html
|
||||
func parseMountInfoString(mountString string) (*MountInfo, error) {
|
||||
var err error
|
||||
|
||||
mountInfo := strings.Split(mountString, " ")
|
||||
mountInfoLength := len(mountInfo)
|
||||
if mountInfoLength < 10 {
|
||||
return nil, fmt.Errorf("%w: Too few fields in mount string: %s", ErrFileParse, mountString)
|
||||
fields := strings.Split(mountString, " - ")
|
||||
if len(fields) != 2 {
|
||||
return nil, fmt.Errorf("%w: Could not split hyphen separator: %s", ErrFileParse, mountString)
|
||||
}
|
||||
|
||||
if mountInfo[mountInfoLength-4] != "-" {
|
||||
return nil, fmt.Errorf("%w: couldn't find separator in expected field: %s", ErrFileParse, mountInfo[mountInfoLength-4])
|
||||
mountInfo := strings.Split(fields[0], " ")
|
||||
if len(mountInfo) < 6 {
|
||||
return nil, fmt.Errorf("%w: Too few fields in mount string: %s", ErrFileParse, mountString)
|
||||
}
|
||||
|
||||
mount := &MountInfo{
|
||||
@@ -90,28 +91,36 @@ func parseMountInfoString(mountString string) (*MountInfo, error) {
|
||||
Root: mountInfo[3],
|
||||
MountPoint: mountInfo[4],
|
||||
Options: mountOptionsParser(mountInfo[5]),
|
||||
OptionalFields: nil,
|
||||
FSType: mountInfo[mountInfoLength-3],
|
||||
Source: mountInfo[mountInfoLength-2],
|
||||
SuperOptions: mountOptionsParser(mountInfo[mountInfoLength-1]),
|
||||
OptionalFields: map[string]string{},
|
||||
}
|
||||
|
||||
mount.MountID, err = strconv.Atoi(mountInfo[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: mount ID: %q", ErrFileParse, mount.MountID)
|
||||
return nil, fmt.Errorf("%w: mount ID: %q", ErrFileParse, mountInfo[0])
|
||||
}
|
||||
mount.ParentID, err = strconv.Atoi(mountInfo[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: parent ID: %q", ErrFileParse, mount.ParentID)
|
||||
return nil, fmt.Errorf("%w: parent ID: %q", ErrFileParse, mountInfo[1])
|
||||
}
|
||||
|
||||
// Has optional fields, which is a space separated list of values.
|
||||
// Example: shared:2 master:7
|
||||
if mountInfo[6] != "" {
|
||||
mount.OptionalFields, err = mountOptionsParseOptionalFields(mountInfo[6 : mountInfoLength-4])
|
||||
if len(mountInfo) > 6 {
|
||||
mount.OptionalFields, err = mountOptionsParseOptionalFields(mountInfo[6:])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: %w", ErrFileParse, err)
|
||||
}
|
||||
}
|
||||
|
||||
mountInfo = strings.SplitN(fields[1], " ", 3)
|
||||
if len(mountInfo) != 3 {
|
||||
return nil, fmt.Errorf("%w: Too few fields after separator: %s", ErrFileParse, mountString)
|
||||
}
|
||||
|
||||
mount.FSType = mountInfo[0]
|
||||
mount.Source = mountInfo[1]
|
||||
mount.SuperOptions = mountOptionsParser(mountInfo[2])
|
||||
|
||||
return mount, nil
|
||||
}
|
||||
|
||||
@@ -148,19 +157,17 @@ func mountOptionsParseOptionalFields(o []string) (map[string]string, error) {
|
||||
func mountOptionsParser(mountOptions string) map[string]string {
|
||||
opts := make(map[string]string)
|
||||
for opt := range strings.SplitSeq(mountOptions, ",") {
|
||||
splitOption := strings.Split(opt, "=")
|
||||
splitOption := strings.SplitN(opt, "=", 2)
|
||||
if len(splitOption) < 2 {
|
||||
key := splitOption[0]
|
||||
opts[key] = ""
|
||||
opts[splitOption[0]] = ""
|
||||
} else {
|
||||
key, value := splitOption[0], splitOption[1]
|
||||
opts[key] = value
|
||||
opts[splitOption[0]] = splitOption[1]
|
||||
}
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
// readMountInfo reads a full mountinfo file (no 1 MiB cap, unlike util.ReadFileNoStat).
|
||||
// readMountInfo reads a full mountinfo file (no 1 MiB cap, unlike parsers.ReadFileNoStat).
|
||||
func readMountInfo(path string) ([]byte, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// A ConntrackStatEntry represents one line from net/stat/nf_conntrack
|
||||
@@ -49,7 +49,7 @@ func (fs FS) ConntrackStat() ([]ConntrackStatEntry, error) {
|
||||
// Parses a slice of ConntrackStatEntries from the given filepath.
|
||||
func readConntrackStat(path string) ([]ConntrackStatEntry, error) {
|
||||
// This file is small and can be read with one syscall.
|
||||
b, err := util.ReadFileNoStat(path)
|
||||
b, err := parsers.ReadFileNoStat(path)
|
||||
if err != nil {
|
||||
// Do not wrap this error so the caller can detect os.IsNotExist and
|
||||
// similar conditions.
|
||||
@@ -84,7 +84,7 @@ func parseConntrackStat(r io.Reader) ([]ConntrackStatEntry, error) {
|
||||
|
||||
// Parses a ConntrackStatEntry from given array of fields.
|
||||
func parseConntrackStatEntry(fields []string) (*ConntrackStatEntry, error) {
|
||||
entries, err := util.ParseHexUint64s(fields)
|
||||
entries, err := parsers.ParseHexUint64s(fields)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: Cannot parse entry: %d: %w", ErrFileParse, entries, err)
|
||||
}
|
||||
|
||||
+9
-9
@@ -178,7 +178,7 @@ func parseNetIPSocketLine(fields []string, isUDP bool) (*netIPSocketLine, error)
|
||||
}
|
||||
|
||||
if line.Sl, err = strconv.ParseUint(s[0], 0, 64); err != nil {
|
||||
return nil, fmt.Errorf("%w: Unable to parse sl field in %q: %w", ErrFileParse, line.Sl, err)
|
||||
return nil, fmt.Errorf("%w: Unable to parse sl field in %q: %w", ErrFileParse, s[0], err)
|
||||
}
|
||||
// local_address
|
||||
l := strings.Split(fields[1], ":")
|
||||
@@ -189,7 +189,7 @@ func parseNetIPSocketLine(fields []string, isUDP bool) (*netIPSocketLine, error)
|
||||
return nil, err
|
||||
}
|
||||
if line.LocalPort, err = strconv.ParseUint(l[1], 16, 64); err != nil {
|
||||
return nil, fmt.Errorf("%w: Unable to parse local_address port value line %q: %w", ErrFileParse, line.LocalPort, err)
|
||||
return nil, fmt.Errorf("%w: Unable to parse local_address port value line %q: %w", ErrFileParse, l[1], err)
|
||||
}
|
||||
|
||||
// remote_address
|
||||
@@ -201,12 +201,12 @@ func parseNetIPSocketLine(fields []string, isUDP bool) (*netIPSocketLine, error)
|
||||
return nil, err
|
||||
}
|
||||
if line.RemPort, err = strconv.ParseUint(r[1], 16, 64); err != nil {
|
||||
return nil, fmt.Errorf("%w: Cannot parse rem_address port value in %q: %w", ErrFileParse, line.RemPort, err)
|
||||
return nil, fmt.Errorf("%w: Cannot parse rem_address port value in %q: %w", ErrFileParse, r[1], err)
|
||||
}
|
||||
|
||||
// st
|
||||
if line.St, err = strconv.ParseUint(fields[3], 16, 64); err != nil {
|
||||
return nil, fmt.Errorf("%w: Cannot parse st value in %q: %w", ErrFileParse, line.St, err)
|
||||
return nil, fmt.Errorf("%w: Cannot parse st value in %q: %w", ErrFileParse, fields[3], err)
|
||||
}
|
||||
|
||||
// tx_queue and rx_queue
|
||||
@@ -219,27 +219,27 @@ func parseNetIPSocketLine(fields []string, isUDP bool) (*netIPSocketLine, error)
|
||||
)
|
||||
}
|
||||
if line.TxQueue, err = strconv.ParseUint(q[0], 16, 64); err != nil {
|
||||
return nil, fmt.Errorf("%w: Cannot parse tx_queue value in %q: %w", ErrFileParse, line.TxQueue, err)
|
||||
return nil, fmt.Errorf("%w: Cannot parse tx_queue value in %q: %w", ErrFileParse, q[0], err)
|
||||
}
|
||||
if line.RxQueue, err = strconv.ParseUint(q[1], 16, 64); err != nil {
|
||||
return nil, fmt.Errorf("%w: Cannot parse trx_queue value in %q: %w", ErrFileParse, line.RxQueue, err)
|
||||
return nil, fmt.Errorf("%w: Cannot parse trx_queue value in %q: %w", ErrFileParse, q[1], err)
|
||||
}
|
||||
|
||||
// uid
|
||||
if line.UID, err = strconv.ParseUint(fields[7], 0, 64); err != nil {
|
||||
return nil, fmt.Errorf("%w: Cannot parse UID value in %q: %w", ErrFileParse, line.UID, err)
|
||||
return nil, fmt.Errorf("%w: Cannot parse UID value in %q: %w", ErrFileParse, fields[7], err)
|
||||
}
|
||||
|
||||
// inode
|
||||
if line.Inode, err = strconv.ParseUint(fields[9], 0, 64); err != nil {
|
||||
return nil, fmt.Errorf("%w: Cannot parse inode value in %q: %w", ErrFileParse, line.Inode, err)
|
||||
return nil, fmt.Errorf("%w: Cannot parse inode value in %q: %w", ErrFileParse, fields[9], err)
|
||||
}
|
||||
|
||||
// drops
|
||||
if isUDP {
|
||||
drops, err := strconv.ParseUint(fields[12], 0, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: Cannot parse drops value in %q: %w", ErrFileParse, drops, err)
|
||||
return nil, fmt.Errorf("%w: Cannot parse drops value in %q: %w", ErrFileParse, fields[12], err)
|
||||
}
|
||||
line.Drops = &drops
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// NetProtocolStats stores the contents from /proc/net/protocols.
|
||||
@@ -71,7 +71,7 @@ type NetProtocolCapabilities struct {
|
||||
// Linux 2.6.12-rc2 - https://elixir.bootlin.com/linux/v2.6.12-rc2/source/net/core/sock.c#L1452
|
||||
// Linux 5.10 - https://elixir.bootlin.com/linux/v5.10.4/source/net/core/sock.c#L3586
|
||||
func (fs FS) NetProtocols() (NetProtocolStats, error) {
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path("net/protocols"))
|
||||
data, err := parsers.ReadFileNoStat(fs.proc.Path("net/protocols"))
|
||||
if err != nil {
|
||||
return NetProtocolStats{}, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -50,7 +50,7 @@ func (fs FS) NetRoute() ([]NetRouteLine, error) {
|
||||
}
|
||||
|
||||
func readNetRoute(path string) ([]NetRouteLine, error) {
|
||||
b, err := util.ReadFileNoStat(path)
|
||||
b, err := parsers.ReadFileNoStat(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// A NetSockstat contains the output of /proc/net/sockstat{,6} for IPv4 or IPv6,
|
||||
@@ -60,7 +60,7 @@ func (fs FS) NetSockstat6() (*NetSockstat, error) {
|
||||
// readSockstat opens and parses a NetSockstat from the input file.
|
||||
func readSockstat(name string) (*NetSockstat, error) {
|
||||
// This file is small and can be read with one syscall.
|
||||
b, err := util.ReadFileNoStat(name)
|
||||
b, err := parsers.ReadFileNoStat(name)
|
||||
if err != nil {
|
||||
// Do not wrap this error so the caller can detect os.IsNotExist and
|
||||
// similar conditions.
|
||||
@@ -124,7 +124,7 @@ func parseSockstatKVs(kvs []string) (map[string]int, error) {
|
||||
// Iterate two values at a time to gather key/value pairs.
|
||||
out := make(map[string]int, len(kvs)/2)
|
||||
for i := 0; i < len(kvs); i += 2 {
|
||||
vp := util.NewValueParser(kvs[i+1])
|
||||
vp := parsers.NewValueParser(kvs[i+1])
|
||||
out[kvs[i]] = vp.Int()
|
||||
|
||||
if err := vp.Err(); err != nil {
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// For the proc file format details,
|
||||
@@ -57,7 +57,7 @@ var softNetProcFile = "net/softnet_stat"
|
||||
|
||||
// NetSoftnetStat reads data from /proc/net/softnet_stat.
|
||||
func (fs FS) NetSoftnetStat() ([]SoftnetStat, error) {
|
||||
b, err := util.ReadFileNoStat(fs.proc.Path(softNetProcFile))
|
||||
b, err := parsers.ReadFileNoStat(fs.proc.Path(softNetProcFile))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -32,9 +32,9 @@ type TLSStat struct {
|
||||
TLSCurrTxDevice int
|
||||
// number of RX sessions currently installed where NIC handles cryptography
|
||||
TLSCurrRxDevice int
|
||||
//number of TX sessions opened with host cryptography
|
||||
// number of TX sessions opened with host cryptography
|
||||
TLSTxSw int
|
||||
//number of RX sessions opened with host cryptography
|
||||
// number of RX sessions opened with host cryptography
|
||||
TLSRxSw int
|
||||
// number of TX sessions opened with NIC cryptography
|
||||
TLSTxDevice int
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Wireless models the content of /proc/net/wireless.
|
||||
@@ -61,7 +61,7 @@ type Wireless struct {
|
||||
|
||||
// Wireless returns kernel wireless statistics.
|
||||
func (fs FS) Wireless() ([]*Wireless, error) {
|
||||
b, err := util.ReadFileNoStat(fs.proc.Path("net/wireless"))
|
||||
b, err := parsers.ReadFileNoStat(fs.proc.Path("net/wireless"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+10
-1
@@ -61,7 +61,12 @@ func parseNetstat(filePath string) (NetStat, error) {
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
scanner.Scan()
|
||||
if !scanner.Scan() {
|
||||
if err := scanner.Err(); err != nil {
|
||||
return NetStat{}, err
|
||||
}
|
||||
return netStat, nil
|
||||
}
|
||||
|
||||
// First string is always a header for stats
|
||||
var headers []string
|
||||
@@ -78,5 +83,9 @@ func parseNetstat(filePath string) (NetStat, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return NetStat{}, err
|
||||
}
|
||||
|
||||
return netStat, nil
|
||||
}
|
||||
+2
-2
@@ -18,7 +18,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
const nfNetLinkQueueFormat = "%d %d %d %d %d %d %d %d %d"
|
||||
@@ -48,7 +48,7 @@ type NFNetLinkQueue struct {
|
||||
|
||||
// NFNetLinkQueue returns information about current state of netfilter queues.
|
||||
func (fs FS) NFNetLinkQueue() ([]NFNetLinkQueue, error) {
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path("net/netfilter/nfnetlink_queue"))
|
||||
data, err := parsers.ReadFileNoStat(fs.proc.Path("net/netfilter/nfnetlink_queue"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Proc provides information about a running process.
|
||||
@@ -128,7 +128,7 @@ func (fs FS) AllProcs() (Procs, error) {
|
||||
|
||||
// CmdLine returns the command line of a process.
|
||||
func (p Proc) CmdLine() ([]string, error) {
|
||||
data, err := util.ReadFileNoStat(p.path("cmdline"))
|
||||
data, err := parsers.ReadFileNoStat(p.path("cmdline"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func (p Proc) Wchan() (string, error) {
|
||||
|
||||
// Comm returns the command name of a process.
|
||||
func (p Proc) Comm() (string, error) {
|
||||
data, err := util.ReadFileNoStat(p.path("comm"))
|
||||
data, err := parsers.ReadFileNoStat(p.path("comm"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -281,7 +281,7 @@ func (p Proc) MountStats() ([]*Mount, error) {
|
||||
// It supplies information missing in `/proc/self/mounts` and
|
||||
// fixes various other problems with that file too.
|
||||
func (p Proc) MountInfo() ([]*MountInfo, error) {
|
||||
data, err := util.ReadFileNoStat(p.path("mountinfo"))
|
||||
data, err := parsers.ReadFileNoStat(p.path("mountinfo"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Cgroup models one line from /proc/[pid]/cgroup. Each Cgroup struct describes the placement of a PID inside a
|
||||
@@ -90,7 +90,7 @@ func parseCgroups(data []byte) ([]Cgroup, error) {
|
||||
// control hierarchy running on this system. On every system (v1 and v2), all hierarchies contain all processes,
|
||||
// so the len of the returned struct is equal to the number of active hierarchies on this system.
|
||||
func (p Proc) Cgroups() ([]Cgroup, error) {
|
||||
data, err := util.ReadFileNoStat(p.path("cgroup"))
|
||||
data, err := parsers.ReadFileNoStat(p.path("cgroup"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// CgroupSummary models one line from /proc/cgroups.
|
||||
@@ -90,7 +90,7 @@ func parseCgroupSummary(data []byte) ([]CgroupSummary, error) {
|
||||
|
||||
// CgroupSummarys returns information about current /proc/cgroups.
|
||||
func (fs FS) CgroupSummarys() ([]CgroupSummary, error) {
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path("cgroups"))
|
||||
data, err := parsers.ReadFileNoStat(fs.proc.Path("cgroups"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+3
-3
@@ -16,20 +16,20 @@ package procfs
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Environ reads process environments from `/proc/<pid>/environ`.
|
||||
func (p Proc) Environ() ([]string, error) {
|
||||
environments := make([]string, 0)
|
||||
|
||||
data, err := util.ReadFileNoStat(p.path("environ"))
|
||||
data, err := parsers.ReadFileNoStat(p.path("environ"))
|
||||
if err != nil {
|
||||
return environments, err
|
||||
}
|
||||
|
||||
environments = strings.Split(string(data), "\000")
|
||||
if len(environments) > 0 {
|
||||
if environments[len(environments)-1] == "" {
|
||||
environments = environments[:len(environments)-1]
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -49,7 +49,7 @@ type ProcFDInfo struct {
|
||||
|
||||
// FDInfo constructor. On kernels older than 3.8, InotifyInfos will always be empty.
|
||||
func (p Proc) FDInfo(fd string) (*ProcFDInfo, error) {
|
||||
data, err := util.ReadFileNoStat(p.path("fdinfo", fd))
|
||||
data, err := parsers.ReadFileNoStat(p.path("fdinfo", fd))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Interrupt represents a single interrupt line.
|
||||
@@ -42,7 +42,7 @@ type Interrupts map[string]Interrupt
|
||||
|
||||
// Interrupts creates a new instance from a given Proc instance.
|
||||
func (p Proc) Interrupts() (Interrupts, error) {
|
||||
data, err := util.ReadFileNoStat(p.fs.proc.Path("interrupts"))
|
||||
data, err := parsers.ReadFileNoStat(p.fs.proc.Path("interrupts"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ package procfs
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// ProcIO models the content of /proc/<pid>/io.
|
||||
@@ -43,7 +43,7 @@ type ProcIO struct {
|
||||
func (p Proc) IO() (ProcIO, error) {
|
||||
pio := ProcIO{}
|
||||
|
||||
data, err := util.ReadFileNoStat(p.path("io"))
|
||||
data, err := parsers.ReadFileNoStat(p.path("io"))
|
||||
if err != nil {
|
||||
return pio, err
|
||||
}
|
||||
|
||||
+1
-4
@@ -74,9 +74,7 @@ const (
|
||||
limitsUnlimited = "unlimited"
|
||||
)
|
||||
|
||||
var (
|
||||
limitsMatch = regexp.MustCompile(`(Max \w+\s??\w*\s?\w*)\s{2,}(\w+)\s+(\w+)`)
|
||||
)
|
||||
var limitsMatch = regexp.MustCompile(`(Max \w+\s??\w*\s?\w*)\s{2,}(\w+)\s+(\w+)`)
|
||||
|
||||
// NewLimits returns the current soft limits of the process.
|
||||
//
|
||||
@@ -101,7 +99,6 @@ func (p Proc) Limits() (ProcLimits, error) {
|
||||
s.Scan() // Skip limits header
|
||||
|
||||
for s.Scan() {
|
||||
//fields := limitsMatch.Split(s.Text(), limitsFields)
|
||||
fields := limitsMatch.FindStringSubmatch(s.Text())
|
||||
if len(fields) != limitsFields {
|
||||
return ProcLimits{}, fmt.Errorf("%w: couldn't parse %q line %q", ErrFileParse, f.Name(), s.Text())
|
||||
|
||||
+8
-8
@@ -61,17 +61,17 @@ type ProcMap struct {
|
||||
// parseDevice parses the device token of a line and converts it to a dev_t
|
||||
// (mkdev) like structure.
|
||||
func parseDevice(s string) (uint64, error) {
|
||||
i := strings.Index(s, ":")
|
||||
if i == -1 {
|
||||
before, after, ok := strings.Cut(s, ":")
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("%w: expected separator `:` in %s", ErrFileParse, s)
|
||||
}
|
||||
|
||||
major, err := strconv.ParseUint(s[0:i], 16, 0)
|
||||
major, err := strconv.ParseUint(before, 16, 0)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
minor, err := strconv.ParseUint(s[i+1:], 16, 0)
|
||||
minor, err := strconv.ParseUint(after, 16, 0)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -91,17 +91,17 @@ func parseAddress(s string) (uintptr, error) {
|
||||
|
||||
// parseAddresses parses the start-end address.
|
||||
func parseAddresses(s string) (uintptr, uintptr, error) {
|
||||
idx := strings.Index(s, "-")
|
||||
if idx == -1 {
|
||||
before, after, ok := strings.Cut(s, "-")
|
||||
if !ok {
|
||||
return 0, 0, fmt.Errorf("%w: expected separator `-` in %s", ErrFileParse, s)
|
||||
}
|
||||
|
||||
saddr, err := parseAddress(s[0:idx])
|
||||
saddr, err := parseAddress(before)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
eaddr, err := parseAddress(s[idx+1:])
|
||||
eaddr, err := parseAddress(after)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
+36
-2
@@ -21,7 +21,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// ProcNetstat models the content of /proc/<pid>/net/netstat.
|
||||
@@ -146,6 +146,20 @@ type TcpExt struct { // nolint:revive
|
||||
TCPMTUPFail *float64
|
||||
TCPMTUPSuccess *float64
|
||||
TCPWqueueTooBig *float64
|
||||
|
||||
// Legacy TcpExt counters dropped from recent kernels' TcpExt table;
|
||||
// modeled so consumers retain metric parity with older kernels that
|
||||
// still print them in /proc/net/netstat.
|
||||
TCPLoss *float64
|
||||
PAWSPassive *float64
|
||||
TCPForwardRetrans *float64
|
||||
TCPSchedulerFailed *float64
|
||||
TCPPrequeued *float64
|
||||
TCPDirectCopyFromBacklog *float64
|
||||
TCPDirectCopyFromPrequeue *float64
|
||||
TCPPrequeueDropped *float64
|
||||
TCPFACKReorder *float64
|
||||
TCPHPHitsToUser *float64
|
||||
}
|
||||
|
||||
type IpExt struct { // nolint:revive
|
||||
@@ -171,7 +185,7 @@ type IpExt struct { // nolint:revive
|
||||
|
||||
func (p Proc) Netstat() (ProcNetstat, error) {
|
||||
filename := p.path("net/netstat")
|
||||
data, err := util.ReadFileNoStat(filename)
|
||||
data, err := parsers.ReadFileNoStat(filename)
|
||||
if err != nil {
|
||||
return ProcNetstat{PID: p.PID}, err
|
||||
}
|
||||
@@ -396,6 +410,26 @@ func parseProcNetstat(r io.Reader, fileName string) (ProcNetstat, error) {
|
||||
procNetstat.TCPMTUPSuccess = &value
|
||||
case "TCPWqueueTooBig":
|
||||
procNetstat.TCPWqueueTooBig = &value
|
||||
case "TCPLoss":
|
||||
procNetstat.TCPLoss = &value
|
||||
case "PAWSPassive":
|
||||
procNetstat.PAWSPassive = &value
|
||||
case "TCPForwardRetrans":
|
||||
procNetstat.TCPForwardRetrans = &value
|
||||
case "TCPSchedulerFailed":
|
||||
procNetstat.TCPSchedulerFailed = &value
|
||||
case "TCPPrequeued":
|
||||
procNetstat.TCPPrequeued = &value
|
||||
case "TCPDirectCopyFromBacklog":
|
||||
procNetstat.TCPDirectCopyFromBacklog = &value
|
||||
case "TCPDirectCopyFromPrequeue":
|
||||
procNetstat.TCPDirectCopyFromPrequeue = &value
|
||||
case "TCPPrequeueDropped":
|
||||
procNetstat.TCPPrequeueDropped = &value
|
||||
case "TCPFACKReorder":
|
||||
procNetstat.TCPFACKReorder = &value
|
||||
case "TCPHPHitsToUser":
|
||||
procNetstat.TCPHPHitsToUser = &value
|
||||
}
|
||||
case "IpExt":
|
||||
switch key {
|
||||
|
||||
+5
-5
@@ -30,7 +30,7 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
const lineFormat = "avg10=%f avg60=%f avg300=%f total=%d"
|
||||
@@ -59,7 +59,7 @@ type PSIStats struct {
|
||||
// resource from /proc/pressure/<resource>. At time of writing this can be
|
||||
// either "cpu", "memory" or "io".
|
||||
func (fs FS) PSIStatsForResource(resource string) (PSIStats, error) {
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path(fmt.Sprintf("%s/%s", "pressure", resource)))
|
||||
data, err := parsers.ReadFileNoStat(fs.proc.Path(fmt.Sprintf("%s/%s", "pressure", resource)))
|
||||
if err != nil {
|
||||
return PSIStats{}, fmt.Errorf("%w: psi_stats: unavailable for %q: %w", ErrFileRead, resource, err)
|
||||
}
|
||||
@@ -74,18 +74,18 @@ func parsePSIStats(r io.Reader) (PSIStats, error) {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
l := scanner.Text()
|
||||
prefix := strings.Split(l, " ")[0]
|
||||
prefix, _, _ := strings.Cut(l, " ")
|
||||
switch prefix {
|
||||
case "some":
|
||||
psi := PSILine{}
|
||||
_, err := fmt.Sscanf(l, fmt.Sprintf("some %s", lineFormat), &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total)
|
||||
_, err := fmt.Sscanf(l, "some "+lineFormat, &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total)
|
||||
if err != nil {
|
||||
return PSIStats{}, err
|
||||
}
|
||||
psiStats.Some = &psi
|
||||
case "full":
|
||||
psi := PSILine{}
|
||||
_, err := fmt.Sscanf(l, fmt.Sprintf("full %s", lineFormat), &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total)
|
||||
_, err := fmt.Sscanf(l, "full "+lineFormat, &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total)
|
||||
if err != nil {
|
||||
return PSIStats{}, err
|
||||
}
|
||||
|
||||
+4
-6
@@ -23,13 +23,11 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
var (
|
||||
// Match the header line before each mapped zone in `/proc/pid/smaps`.
|
||||
procSMapsHeaderLine = regexp.MustCompile(`^[a-f0-9].*$`)
|
||||
)
|
||||
// Match the header line before each mapped zone in `/proc/pid/smaps`.
|
||||
var procSMapsHeaderLine = regexp.MustCompile(`^[a-f0-9].*$`)
|
||||
|
||||
type ProcSMapsRollup struct {
|
||||
// Amount of the mapping that is currently resident in RAM.
|
||||
@@ -60,7 +58,7 @@ type ProcSMapsRollup struct {
|
||||
// If smaps_rollup does not exists (require kernel >= 4.15), the content of /proc/pid/smaps will
|
||||
// we read and summed.
|
||||
func (p Proc) ProcSMapsRollup() (ProcSMapsRollup, error) {
|
||||
data, err := util.ReadFileNoStat(p.path("smaps_rollup"))
|
||||
data, err := parsers.ReadFileNoStat(p.path("smaps_rollup"))
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
return p.procSMapsRollupManual()
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// ProcSnmp models the content of /proc/<pid>/net/snmp.
|
||||
@@ -135,7 +135,7 @@ type UdpLite struct { // nolint:revive
|
||||
|
||||
func (p Proc) Snmp() (ProcSnmp, error) {
|
||||
filename := p.path("net/snmp")
|
||||
data, err := util.ReadFileNoStat(filename)
|
||||
data, err := parsers.ReadFileNoStat(filename)
|
||||
if err != nil {
|
||||
return ProcSnmp{PID: p.PID}, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// ProcSnmp6 models the content of /proc/<pid>/net/snmp6.
|
||||
@@ -140,7 +140,7 @@ type UdpLite6 struct { // nolint:revive
|
||||
|
||||
func (p Proc) Snmp6() (ProcSnmp6, error) {
|
||||
filename := p.path("net/snmp6")
|
||||
data, err := util.ReadFileNoStat(filename)
|
||||
data, err := parsers.ReadFileNoStat(filename)
|
||||
if err != nil {
|
||||
// On systems with IPv6 disabled, this file won't exist.
|
||||
// Do nothing.
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Originally, this USER_HZ value was dynamically retrieved via a sysconf call
|
||||
@@ -134,7 +134,7 @@ func (p Proc) NewStat() (ProcStat, error) {
|
||||
|
||||
// Stat returns the current status information of the process.
|
||||
func (p Proc) Stat() (ProcStat, error) {
|
||||
data, err := util.ReadFileNoStat(p.path("stat"))
|
||||
data, err := parsers.ReadFileNoStat(p.path("stat"))
|
||||
if err != nil {
|
||||
return ProcStat{}, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// - https://man7.org/linux/man-pages/man5/proc_pid_statm.5.html
|
||||
@@ -53,7 +53,7 @@ func (p Proc) NewStatm() (ProcStatm, error) {
|
||||
|
||||
// Statm returns the current memory usage information of the process.
|
||||
func (p Proc) Statm() (ProcStatm, error) {
|
||||
data, err := util.ReadFileNoStat(p.path("statm"))
|
||||
data, err := parsers.ReadFileNoStat(p.path("statm"))
|
||||
if err != nil {
|
||||
return ProcStatm{}, err
|
||||
}
|
||||
|
||||
+3
-4
@@ -20,7 +20,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// ProcStatus provides status information about the process,
|
||||
@@ -100,7 +100,7 @@ type ProcStatus struct {
|
||||
|
||||
// NewStatus returns the current status information of the process.
|
||||
func (p Proc) NewStatus() (ProcStatus, error) {
|
||||
data, err := util.ReadFileNoStat(p.path("status"))
|
||||
data, err := parsers.ReadFileNoStat(p.path("status"))
|
||||
if err != nil {
|
||||
return ProcStatus{}, err
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func (p Proc) NewStatus() (ProcStatus, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *ProcStatus) fillStatus(k string, vString string, vUint uint64, vUintBytes uint64) error {
|
||||
func (s *ProcStatus) fillStatus(k, vString string, vUint, vUintBytes uint64) error {
|
||||
switch k {
|
||||
case "Tgid":
|
||||
s.TGID = int(vUint)
|
||||
@@ -261,7 +261,6 @@ func calcCpusAllowedList(cpuString string) []uint64 {
|
||||
cpu, _ := strconv.ParseUint(l[0], 10, 64)
|
||||
g = append(g, cpu)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
slices.Sort(g)
|
||||
|
||||
+3
-4
@@ -17,7 +17,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
func sysctlToPath(sysctl string) string {
|
||||
@@ -25,12 +25,11 @@ func sysctlToPath(sysctl string) string {
|
||||
}
|
||||
|
||||
func (fs FS) SysctlStrings(sysctl string) ([]string, error) {
|
||||
value, err := util.SysReadFile(fs.proc.Path("sys", sysctlToPath(sysctl)))
|
||||
value, err := parsers.SysReadFile(fs.proc.Path("sys", sysctlToPath(sysctl)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return strings.Fields(value), nil
|
||||
|
||||
}
|
||||
|
||||
func (fs FS) SysctlInts(sysctl string) ([]int, error) {
|
||||
@@ -41,7 +40,7 @@ func (fs FS) SysctlInts(sysctl string) ([]int, error) {
|
||||
|
||||
values := make([]int, len(fields))
|
||||
for i, f := range fields {
|
||||
vp := util.NewValueParser(f)
|
||||
vp := parsers.NewValueParser(f)
|
||||
values[i] = vp.Int()
|
||||
if err := vp.Err(); err != nil {
|
||||
return nil, fmt.Errorf("%w: field %d in sysctl %s is not a valid int: %w", ErrFileParse, i, sysctl, err)
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -142,7 +142,7 @@ func (fs FS) SlabInfo() (SlabInfo, error) {
|
||||
// TODO: Consider passing options to allow for parsing different
|
||||
// slabinfo versions. However, slabinfo 2.1 has been stable since
|
||||
// kernel 2.6.10 and later.
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path("slabinfo"))
|
||||
data, err := parsers.ReadFileNoStat(fs.proc.Path("slabinfo"))
|
||||
if err != nil {
|
||||
return SlabInfo{}, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Softirqs represents the softirq statistics.
|
||||
@@ -40,7 +40,7 @@ type Softirqs struct {
|
||||
|
||||
func (fs FS) Softirqs() (Softirqs, error) {
|
||||
fileName := fs.proc.Path("softirqs")
|
||||
data, err := util.ReadFileNoStat(fileName)
|
||||
data, err := parsers.ReadFileNoStat(fileName)
|
||||
if err != nil {
|
||||
return Softirqs{}, err
|
||||
}
|
||||
|
||||
+4
-5
@@ -23,7 +23,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/fs"
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// CPUStat shows how much time the cpu spend in various stages.
|
||||
@@ -135,7 +135,6 @@ func parseSoftIRQStat(line string) (SoftIRQStat, uint64, error) {
|
||||
&softIRQStat.Block, &softIRQStat.BlockIoPoll,
|
||||
&softIRQStat.Tasklet, &softIRQStat.Sched,
|
||||
&softIRQStat.Hrtimer, &softIRQStat.Rcu)
|
||||
|
||||
if err != nil {
|
||||
return SoftIRQStat{}, 0, fmt.Errorf("%w: couldn't parse %q (softirq): %w", ErrFileParse, line, err)
|
||||
}
|
||||
@@ -167,7 +166,7 @@ func (fs FS) NewStat() (Stat, error) {
|
||||
// See: https://www.kernel.org/doc/Documentation/filesystems/proc.txt
|
||||
func (fs FS) Stat() (Stat, error) {
|
||||
fileName := fs.proc.Path("stat")
|
||||
data, err := util.ReadFileNoStat(fileName)
|
||||
data, err := parsers.ReadFileNoStat(fileName)
|
||||
if err != nil {
|
||||
return Stat{}, err
|
||||
}
|
||||
@@ -178,7 +177,7 @@ func (fs FS) Stat() (Stat, error) {
|
||||
return procStat, nil
|
||||
}
|
||||
|
||||
// parseStat parses the metrics from /proc/[pid]/stat.
|
||||
// parseStat parses the metrics from /proc/stat.
|
||||
func parseStat(r io.Reader, fileName string) (Stat, error) {
|
||||
var (
|
||||
scanner = bufio.NewScanner(r)
|
||||
@@ -194,7 +193,7 @@ func parseStat(r io.Reader, fileName string) (Stat, error) {
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
parts := strings.Fields(scanner.Text())
|
||||
parts := strings.Fields(line)
|
||||
// require at least <key> <value>
|
||||
if len(parts) < 2 {
|
||||
continue
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Swap represents an entry in /proc/swaps.
|
||||
@@ -34,7 +34,7 @@ type Swap struct {
|
||||
|
||||
// Swaps returns a slice of all configured swap devices on the system.
|
||||
func (fs FS) Swaps() ([]*Swap, error) {
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path("swaps"))
|
||||
data, err := parsers.ReadFileNoStat(fs.proc.Path("swaps"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+4
-4
@@ -21,7 +21,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// The VM interface is described at
|
||||
@@ -102,11 +102,11 @@ func (fs FS) VM() (*VM, error) {
|
||||
name := filepath.Join(path, f.Name())
|
||||
// ignore errors on read, as there are some write only
|
||||
// in /proc/sys/vm
|
||||
value, err := util.SysReadFile(name)
|
||||
value, err := parsers.SysReadFile(name)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
vp := util.NewValueParser(value)
|
||||
vp := parsers.NewValueParser(value)
|
||||
|
||||
switch f.Name() {
|
||||
case "admin_reserve_kbytes":
|
||||
@@ -143,7 +143,7 @@ func (fs FS) VM() (*VM, error) {
|
||||
stringSlice := strings.Fields(value)
|
||||
pint64Slice := make([]*int64, 0, len(stringSlice))
|
||||
for _, value := range stringSlice {
|
||||
vp := util.NewValueParser(value)
|
||||
vp := parsers.NewValueParser(value)
|
||||
pint64Slice = append(pint64Slice, vp.PInt64())
|
||||
}
|
||||
vm.LowmemReserveRatio = pint64Slice
|
||||
|
||||
+3
-4
@@ -22,7 +22,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
"github.com/prometheus/procfs/internal/parsers"
|
||||
)
|
||||
|
||||
// Zoneinfo holds info parsed from /proc/zoneinfo.
|
||||
@@ -84,7 +84,6 @@ func (fs FS) Zoneinfo() ([]Zoneinfo, error) {
|
||||
}
|
||||
|
||||
func parseZoneinfo(zoneinfoData []byte) ([]Zoneinfo, error) {
|
||||
|
||||
zoneinfo := []Zoneinfo{}
|
||||
|
||||
for block := range bytes.SplitSeq(zoneinfoData, []byte("\nNode")) {
|
||||
@@ -103,7 +102,7 @@ func parseZoneinfo(zoneinfoData []byte) ([]Zoneinfo, error) {
|
||||
if len(parts) < 2 {
|
||||
continue
|
||||
}
|
||||
vp := util.NewValueParser(parts[1])
|
||||
vp := parsers.NewValueParser(parts[1])
|
||||
switch parts[0] {
|
||||
case "nr_free_pages":
|
||||
zoneinfoElement.NrFreePages = vp.PInt64()
|
||||
@@ -179,7 +178,7 @@ func parseZoneinfo(zoneinfoData []byte) ([]Zoneinfo, error) {
|
||||
protectionValues = strings.Replace(protectionValues, ")", "", 1)
|
||||
protectionValues = strings.TrimSpace(protectionValues)
|
||||
protectionStringMap := strings.Split(protectionValues, ", ")
|
||||
val, err := util.ParsePInt64s(protectionStringMap)
|
||||
val, err := parsers.ParsePInt64s(protectionStringMap)
|
||||
if err == nil {
|
||||
zoneinfoElement.Protection = val
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user