diff --git a/.golangci.yml b/.golangci.yml index eac920ba..23ecd450 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -34,14 +34,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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 853eb9d4..812a71bb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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") ``` diff --git a/bcachefs/get.go b/bcachefs/get.go index 101ec297..b748228a 100644 --- a/bcachefs/get.go +++ b/bcachefs/get.go @@ -22,7 +22,7 @@ import ( "strings" "github.com/prometheus/procfs/internal/fs" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // FS represents the pseudo-filesystem sys, which provides an interface to @@ -96,7 +96,7 @@ func (r *reader) readFile(n string) string { if r.err != nil { return "" } - b, err := util.ReadFileNoStat(filepath.Join(r.path, n)) + b, err := parsers.ReadFileNoStat(filepath.Join(r.path, n)) if err != nil { if !os.IsNotExist(err) { r.err = err @@ -467,7 +467,7 @@ func parseDevices(fsPath string) (map[string]*DeviceStats, error) { } func readSysfsFile(path string) string { - data, err := util.ReadFileNoStat(path) + data, err := parsers.ReadFileNoStat(path) if err != nil { return "" } @@ -475,7 +475,7 @@ func readSysfsFile(path string) string { } func readUintFile(path string) (uint64, error) { - data, err := util.ReadFileNoStat(path) + data, err := parsers.ReadFileNoStat(path) if err != nil { if os.IsNotExist(err) { return 0, nil diff --git a/blockdevice/dm_multipath.go b/blockdevice/dm_multipath.go index ebcacb85..d6ebca4f 100644 --- a/blockdevice/dm_multipath.go +++ b/blockdevice/dm_multipath.go @@ -19,7 +19,7 @@ import ( "strings" "github.com/prometheus/procfs" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // DMMultipathDevice contains information about a single DM-multipath device @@ -68,7 +68,7 @@ func (fs FS) DMMultipathDevices() ([]DMMultipathDevice, error) { continue } - uuid, err := util.SysReadFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockDM, "uuid")) + uuid, err := parsers.SysReadFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockDM, "uuid")) if err != nil { // dm/uuid missing means this is not a device-mapper device; skip it. if os.IsNotExist(err) { @@ -80,17 +80,17 @@ func (fs FS) DMMultipathDevices() ([]DMMultipathDevice, error) { continue } - name, err := util.SysReadFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockDM, "name")) + name, err := parsers.SysReadFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockDM, "name")) if err != nil { return nil, fmt.Errorf("failed to read dm/name for %s: %w", entry.Name(), err) } - suspendedVal, err := util.ReadUintFromFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockDM, "suspended")) + suspendedVal, err := parsers.ReadUintFromFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockDM, "suspended")) if err != nil { return nil, fmt.Errorf("failed to read dm/suspended for %s: %w", entry.Name(), err) } - sectors, err := util.ReadUintFromFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockSize)) + sectors, err := parsers.ReadUintFromFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockSize)) if err != nil { return nil, fmt.Errorf("failed to read size for %s: %w", entry.Name(), err) } @@ -128,7 +128,7 @@ func (fs FS) dmMultipathPaths(dmDevice string) ([]DMMultipathPath, error) { paths := make([]DMMultipathPath, 0, len(entries)) for _, entry := range entries { - state, err := util.SysReadFile(fs.sys.Path(sysBlockPath, entry.Name(), sysDevicePath, "state")) + state, err := parsers.SysReadFile(fs.sys.Path(sysBlockPath, entry.Name(), sysDevicePath, "state")) if err != nil { return nil, fmt.Errorf("failed to read device/state for %s: %w", entry.Name(), err) } diff --git a/blockdevice/stats.go b/blockdevice/stats.go index 49470bba..a3c003fb 100644 --- a/blockdevice/stats.go +++ b/blockdevice/stats.go @@ -23,7 +23,7 @@ import ( "github.com/prometheus/procfs" "github.com/prometheus/procfs/internal/fs" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // Info contains identifying information for a block device such as a disk drive. @@ -392,7 +392,7 @@ func (fs FS) SysBlockDeviceQueueStats(device string) (BlockQueueStats, error) { "max_discard_segments": &stat.MaxDiscardSegments, "write_zeroes_max_bytes": &stat.WriteZeroesMaxBytes, } { - val, err := util.ReadUintFromFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, file)) + val, err := parsers.ReadUintFromFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, file)) if err != nil { return BlockQueueStats{}, err } @@ -403,7 +403,7 @@ func (fs FS) SysBlockDeviceQueueStats(device string) (BlockQueueStats, error) { "io_poll_delay": &stat.IOPollDelay, "wbt_lat_usec": &stat.WBTLatUSec, } { - val, err := util.ReadIntFromFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, file)) + val, err := parsers.ReadIntFromFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, file)) if err != nil { return BlockQueueStats{}, err } @@ -414,13 +414,13 @@ func (fs FS) SysBlockDeviceQueueStats(device string) (BlockQueueStats, error) { "write_cache": &stat.WriteCache, "zoned": &stat.Zoned, } { - val, err := util.SysReadFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, file)) + val, err := parsers.SysReadFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, file)) if err != nil { return BlockQueueStats{}, err } *p = val } - scheduler, err := util.SysReadFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, "scheduler")) + scheduler, err := parsers.SysReadFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, "scheduler")) if err != nil { return BlockQueueStats{}, err } @@ -434,7 +434,7 @@ func (fs FS) SysBlockDeviceQueueStats(device string) (BlockQueueStats, error) { } stat.SchedulerList = schedulers // optional - throttleSampleTime, err := util.ReadUintFromFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, "throttle_sample_time")) + throttleSampleTime, err := parsers.ReadUintFromFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, "throttle_sample_time")) if err == nil { stat.ThrottleSampleTime = &throttleSampleTime } @@ -449,7 +449,7 @@ func (fs FS) SysBlockDeviceMapperInfo(device string) (DeviceMapperInfo, error) { "suspended": &info.Suspended, "use_blk_mq": &info.UseBlkMQ, } { - val, err := util.ReadUintFromFile(fs.sys.Path(sysBlockPath, device, sysBlockDM, file)) + val, err := parsers.ReadUintFromFile(fs.sys.Path(sysBlockPath, device, sysBlockDM, file)) if err != nil { return DeviceMapperInfo{}, err } @@ -460,7 +460,7 @@ func (fs FS) SysBlockDeviceMapperInfo(device string) (DeviceMapperInfo, error) { "name": &info.Name, "uuid": &info.UUID, } { - val, err := util.SysReadFile(fs.sys.Path(sysBlockPath, device, sysBlockDM, file)) + val, err := parsers.SysReadFile(fs.sys.Path(sysBlockPath, device, sysBlockDM, file)) if err != nil { return DeviceMapperInfo{}, err } @@ -485,7 +485,7 @@ func (fs FS) SysBlockDeviceUnderlyingDevices(device string) (UnderlyingDeviceInf // SysBlockDeviceSize returns the size of the block device from /sys/block//size // in bytes by multiplying the value by the Linux sector length of 512. func (fs FS) SysBlockDeviceSize(device string) (uint64, error) { - size, err := util.ReadUintFromFile(fs.sys.Path(sysBlockPath, device, sysBlockSize)) + size, err := parsers.ReadUintFromFile(fs.sys.Path(sysBlockPath, device, sysBlockSize)) if err != nil { return 0, err } @@ -498,7 +498,7 @@ func (fs FS) SysBlockDeviceSize(device string) (uint64, error) { // non-rotational device (SSD, NVMe). An error is returned if the file // cannot be read or does not contain a valid integer. func (fs FS) SysBlockDeviceRotational(device string) (uint64, error) { - return util.ReadUintFromFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, "rotational")) + return parsers.ReadUintFromFile(fs.sys.Path(sysBlockPath, device, sysBlockQueue, "rotational")) } // SysBlockDeviceIO returns stats for the block device io counters @@ -514,7 +514,7 @@ func (fs FS) SysBlockDeviceIOStat(device string) (IODeviceStats, error) { "ioerr_cnt": &ioDeviceStats.IOErrCount, } { var val uint64 - val, err = util.ReadHexFromFile(fs.sys.Path(sysBlockPath, device, sysDevicePath, file)) + val, err = parsers.ReadHexFromFile(fs.sys.Path(sysBlockPath, device, sysDevicePath, file)) if err != nil { return IODeviceStats{}, err } diff --git a/btrfs/get.go b/btrfs/get.go index 720018ca..107af210 100644 --- a/btrfs/get.go +++ b/btrfs/get.go @@ -24,7 +24,7 @@ import ( "github.com/prometheus/procfs" "github.com/prometheus/procfs/internal/fs" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // FS represents the pseudo-filesystem sys, which provides an interface to @@ -97,7 +97,7 @@ type reader struct { // readFile reads a file relative to the path of the reader. // Non-existing files are ignored. func (r *reader) readFile(n string) string { - b, err := util.SysReadFile(path.Join(r.path, n)) + b, err := parsers.SysReadFile(path.Join(r.path, n)) if err != nil && !os.IsNotExist(err) { r.err = err } diff --git a/cmdline.go b/cmdline.go index 4f1cac1f..6a2e7bb0 100644 --- a/cmdline.go +++ b/cmdline.go @@ -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 } diff --git a/cpuinfo.go b/cpuinfo.go index 4b23d8d6..7a31a455 100644 --- a/cpuinfo.go +++ b/cpuinfo.go @@ -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 } diff --git a/crypto.go b/crypto.go index d93b712e..c4ba05b1 100644 --- a/crypto.go +++ b/crypto.go @@ -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,7 +55,7 @@ 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) @@ -112,7 +112,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": diff --git a/ext4/ext4.go b/ext4/ext4.go index fce5dedf..2b410d09 100644 --- a/ext4/ext4.go +++ b/ext4/ext4.go @@ -19,7 +19,7 @@ import ( "strings" "github.com/prometheus/procfs/internal/fs" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const ( @@ -90,7 +90,7 @@ func (fs FS) ProcStat() ([]*Stats, error) { "msg_count": &s.Messages, } { var val uint64 - val, err = util.ReadUintFromFile(fs.sys.Path(sysFSPath, sysFSExt4Path, name, file)) + val, err = parsers.ReadUintFromFile(fs.sys.Path(sysFSPath, sysFSExt4Path, name, file)) if err == nil { *p = val } diff --git a/fscache.go b/fscache.go index 9dde8570..388295cb 100644 --- a/fscache.go +++ b/fscache.go @@ -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 } diff --git a/internal/util/parse.go b/internal/parsers/parse.go similarity index 99% rename from internal/util/parse.go rename to internal/parsers/parse.go index 30c58720..5789ae5d 100644 --- a/internal/util/parse.go +++ b/internal/parsers/parse.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package util +package parsers import ( "errors" diff --git a/internal/util/readfile.go b/internal/parsers/readfile.go similarity index 98% rename from internal/util/readfile.go rename to internal/parsers/readfile.go index 0e41f71a..c68d2921 100644 --- a/internal/util/readfile.go +++ b/internal/parsers/readfile.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package util +package parsers import ( "io" diff --git a/internal/util/sysreadfile.go b/internal/parsers/sysreadfile.go similarity index 99% rename from internal/util/sysreadfile.go rename to internal/parsers/sysreadfile.go index f6a4a4de..0f72f602 100644 --- a/internal/util/sysreadfile.go +++ b/internal/parsers/sysreadfile.go @@ -13,7 +13,7 @@ //go:build (linux || darwin) && !appengine -package util +package parsers import ( "bytes" diff --git a/internal/util/sysreadfile_compat.go b/internal/parsers/sysreadfile_compat.go similarity index 98% rename from internal/util/sysreadfile_compat.go rename to internal/parsers/sysreadfile_compat.go index c80e082c..6e19c455 100644 --- a/internal/util/sysreadfile_compat.go +++ b/internal/parsers/sysreadfile_compat.go @@ -13,7 +13,7 @@ //go:build (linux && appengine) || (!linux && !darwin) -package util +package parsers import ( "fmt" diff --git a/internal/util/valueparser.go b/internal/parsers/valueparser.go similarity index 99% rename from internal/util/valueparser.go rename to internal/parsers/valueparser.go index e0ed671e..6289fd67 100644 --- a/internal/util/valueparser.go +++ b/internal/parsers/valueparser.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package util +package parsers import ( "strconv" diff --git a/internal/util/valueparser_test.go b/internal/parsers/valueparser_test.go similarity index 79% rename from internal/util/valueparser_test.go rename to internal/parsers/valueparser_test.go index 5219e5fb..c07e5023 100644 --- a/internal/util/valueparser_test.go +++ b/internal/parsers/valueparser_test.go @@ -11,14 +11,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package util_test +package parsers_test import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) func TestValueParser(t *testing.T) { @@ -26,13 +26,13 @@ func TestValueParser(t *testing.T) { name string v string ok bool - fn func(t *testing.T, vp *util.ValueParser) + fn func(t *testing.T, vp *parsers.ValueParser) }{ { name: "ok Int", v: "10", ok: true, - fn: func(t *testing.T, vp *util.ValueParser) { + fn: func(t *testing.T, vp *parsers.ValueParser) { want := 10 got := vp.Int() @@ -44,14 +44,14 @@ func TestValueParser(t *testing.T) { { name: "bad PInt64", v: "hello", - fn: func(_ *testing.T, vp *util.ValueParser) { + fn: func(_ *testing.T, vp *parsers.ValueParser) { _ = vp.PInt64() }, }, { name: "bad hex PInt64", v: "0xhello", - fn: func(_ *testing.T, vp *util.ValueParser) { + fn: func(_ *testing.T, vp *parsers.ValueParser) { _ = vp.PInt64() }, }, @@ -59,7 +59,7 @@ func TestValueParser(t *testing.T) { name: "ok PInt64", v: "1", ok: true, - fn: func(t *testing.T, vp *util.ValueParser) { + fn: func(t *testing.T, vp *parsers.ValueParser) { want := int64(1) got := vp.PInt64() @@ -72,7 +72,7 @@ func TestValueParser(t *testing.T) { name: "ok hex PInt64", v: "0xff", ok: true, - fn: func(t *testing.T, vp *util.ValueParser) { + fn: func(t *testing.T, vp *parsers.ValueParser) { want := int64(255) got := vp.PInt64() @@ -84,14 +84,14 @@ func TestValueParser(t *testing.T) { { name: "bad PUInt64", v: "-42", - fn: func(_ *testing.T, vp *util.ValueParser) { + fn: func(_ *testing.T, vp *parsers.ValueParser) { _ = vp.PUInt64() }, }, { name: "bad hex PUInt64", v: "0xhello", - fn: func(_ *testing.T, vp *util.ValueParser) { + fn: func(_ *testing.T, vp *parsers.ValueParser) { _ = vp.PUInt64() }, }, @@ -99,7 +99,7 @@ func TestValueParser(t *testing.T) { name: "ok PUInt64", v: "1", ok: true, - fn: func(t *testing.T, vp *util.ValueParser) { + fn: func(t *testing.T, vp *parsers.ValueParser) { want := uint64(1) got := vp.PUInt64() @@ -112,7 +112,7 @@ func TestValueParser(t *testing.T) { name: "ok hex PUInt64", v: "0xff", ok: true, - fn: func(t *testing.T, vp *util.ValueParser) { + fn: func(t *testing.T, vp *parsers.ValueParser) { want := uint64(255) got := vp.PUInt64() @@ -125,7 +125,7 @@ func TestValueParser(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - vp := util.NewValueParser(tt.v) + vp := parsers.NewValueParser(tt.v) tt.fn(t, vp) err := vp.Err() diff --git a/ipvs.go b/ipvs.go index 5374da9f..8a6f7374 100644 --- a/ipvs.go +++ b/ipvs.go @@ -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 } diff --git a/iscsi/get.go b/iscsi/get.go index dbc6f1be..3846c714 100644 --- a/iscsi/get.go +++ b/iscsi/get.go @@ -22,7 +22,7 @@ import ( "strconv" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // GetStats is the main iscsi status information func for @@ -108,21 +108,21 @@ func ReadWriteOPS(iqnPath string, tpgt string, lun string) (readmb uint64, readmbPath := filepath.Join(iqnPath, tpgt, "lun", lun, "statistics/scsi_tgt_port/read_mbytes") - readmb, err = util.ReadUintFromFile(readmbPath) + readmb, err = parsers.ReadUintFromFile(readmbPath) if err != nil { return 0, 0, 0, fmt.Errorf("iscsi: ReadWriteOPS: read_mbytes error file %q: %w", readmbPath, err) } writembPath := filepath.Join(iqnPath, tpgt, "lun", lun, "statistics/scsi_tgt_port/write_mbytes") - writemb, err = util.ReadUintFromFile(writembPath) + writemb, err = parsers.ReadUintFromFile(writembPath) if err != nil { return 0, 0, 0, fmt.Errorf("iscsi: ReadWriteOPS: write_mbytes error file %q: %w", writembPath, err) } iopsPath := filepath.Join(iqnPath, tpgt, "lun", lun, "statistics/scsi_tgt_port/in_cmds") - iops, err = util.ReadUintFromFile(iopsPath) + iops, err = parsers.ReadUintFromFile(iopsPath) if err != nil { return 0, 0, 0, fmt.Errorf("iscsi: ReadWriteOPS: in_cmds error file %q: %w", iopsPath, err) } diff --git a/kernel_random.go b/kernel_random.go index e7c5b8cf..cbcd12b4 100644 --- a/kernel_random.go +++ b/kernel_random.go @@ -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 } diff --git a/kernel_tainted.go b/kernel_tainted.go index 8730c99d..9707f028 100644 --- a/kernel_tainted.go +++ b/kernel_tainted.go @@ -16,7 +16,7 @@ package procfs import ( - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // KernelTaintBit represents a single kernel taint flag. @@ -73,7 +73,7 @@ var kernelTaintBitDefs = []struct { // 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 := util.SysReadUintFromFile(fs.proc.Path("sys", "kernel", "tainted")) + value, err := parsers.SysReadUintFromFile(fs.proc.Path("sys", "kernel", "tainted")) if err != nil { return KernelTainted{}, err } diff --git a/loadavg.go b/loadavg.go index c8c78a65..3f12cda0 100644 --- a/loadavg.go +++ b/loadavg.go @@ -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 } diff --git a/meminfo.go b/meminfo.go index 34203831..8e34b071 100644 --- a/meminfo.go +++ b/meminfo.go @@ -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 } diff --git a/mountinfo.go b/mountinfo.go index c0196563..a011edc6 100644 --- a/mountinfo.go +++ b/mountinfo.go @@ -160,7 +160,7 @@ func mountOptionsParser(mountOptions string) map[string]string { 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 { diff --git a/mountinfo_readfull_test.go b/mountinfo_readfull_test.go index fad3f26d..2f4b885d 100644 --- a/mountinfo_readfull_test.go +++ b/mountinfo_readfull_test.go @@ -19,11 +19,11 @@ import ( "strings" "testing" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // TestReadMountInfoExceeds1MiB verifies that a mountinfo file larger than 1 MiB -// is read and parsed in full. The util.ReadFileNoStat helper caps reads at +// is read and parsed in full. The parsers.ReadFileNoStat helper caps reads at // 1 MiB, which truncates and corrupts mountinfo on hosts with a very large // number of mounts (e.g. busy container hosts), so the mountinfo helpers must // not use it. @@ -60,8 +60,8 @@ func TestReadMountInfoExceeds1MiB(t *testing.T) { t.Fatalf("parsed %d mounts, want %d", len(mounts), n) } - // Guard the regression: util.ReadFileNoStat caps at 1 MiB and would truncate. - capped, err := util.ReadFileNoStat(path) + // Guard the regression: parsers.ReadFileNoStat caps at 1 MiB and would truncate. + capped, err := parsers.ReadFileNoStat(path) if err != nil { t.Fatalf("ReadFileNoStat: %v", err) } diff --git a/net_conntrackstat.go b/net_conntrackstat.go index e9ca3570..2d8c72a6 100644 --- a/net_conntrackstat.go +++ b/net_conntrackstat.go @@ -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) } diff --git a/net_protocols.go b/net_protocols.go index eaa996cb..829802cd 100644 --- a/net_protocols.go +++ b/net_protocols.go @@ -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 } diff --git a/net_route.go b/net_route.go index fa3812d9..6c7c480b 100644 --- a/net_route.go +++ b/net_route.go @@ -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 } diff --git a/net_sockstat.go b/net_sockstat.go index 8b221ebf..9470f020 100644 --- a/net_sockstat.go +++ b/net_sockstat.go @@ -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 { diff --git a/net_softnet.go b/net_softnet.go index 4a2dfa18..455ec851 100644 --- a/net_softnet.go +++ b/net_softnet.go @@ -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 } diff --git a/net_wireless.go b/net_wireless.go index f74dd3be..350a328f 100644 --- a/net_wireless.go +++ b/net_wireless.go @@ -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 } diff --git a/nfnetlink_queue.go b/nfnetlink_queue.go index b0a73b11..54fbcf40 100644 --- a/nfnetlink_queue.go +++ b/nfnetlink_queue.go @@ -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 } diff --git a/nfs/parse_nfs.go b/nfs/parse_nfs.go index 9dc01fb2..b94782c9 100644 --- a/nfs/parse_nfs.go +++ b/nfs/parse_nfs.go @@ -19,7 +19,7 @@ import ( "io" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // ParseClientRPCStats returns stats read from /proc/net/rpc/nfs. @@ -35,7 +35,7 @@ func ParseClientRPCStats(r io.Reader) (*ClientRPCStats, error) { return nil, fmt.Errorf("invalid NFS metric line %q", line) } - values, err := util.ParseUint64s(parts[1:]) + values, err := parsers.ParseUint64s(parts[1:]) if err != nil { return nil, fmt.Errorf("error parsing NFS metric line: %w", err) } diff --git a/nfs/parse_nfsd.go b/nfs/parse_nfsd.go index 34125a06..3e256b42 100644 --- a/nfs/parse_nfsd.go +++ b/nfs/parse_nfsd.go @@ -19,7 +19,7 @@ import ( "io" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // ParseServerRPCStats returns stats read from /proc/net/rpc/nfsd. @@ -42,9 +42,9 @@ func ParseServerRPCStats(r io.Reader) (*ServerRPCStats, error) { if len(parts) < 3 { return nil, fmt.Errorf("invalid NFSd th metric line %q", line) } - values, err = util.ParseUint64s(parts[1:3]) + values, err = parsers.ParseUint64s(parts[1:3]) } else { - values, err = util.ParseUint64s(parts[1:]) + values, err = parsers.ParseUint64s(parts[1:]) } if err != nil { return nil, fmt.Errorf("error parsing NFSd metric line: %w", err) diff --git a/proc.go b/proc.go index 39c14aa5..16b9a5e4 100644 --- a/proc.go +++ b/proc.go @@ -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 } diff --git a/proc_cgroup.go b/proc_cgroup.go index 7e8a1229..a5f9ffeb 100644 --- a/proc_cgroup.go +++ b/proc_cgroup.go @@ -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 } diff --git a/proc_cgroups.go b/proc_cgroups.go index 0b275c3b..dbf5e88b 100644 --- a/proc_cgroups.go +++ b/proc_cgroups.go @@ -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 } diff --git a/proc_environ.go b/proc_environ.go index 5b941de0..2ef8b88d 100644 --- a/proc_environ.go +++ b/proc_environ.go @@ -16,14 +16,14 @@ package procfs import ( "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // Environ reads process environments from `/proc//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 } diff --git a/proc_fdinfo.go b/proc_fdinfo.go index fa57761d..9e3e313e 100644 --- a/proc_fdinfo.go +++ b/proc_fdinfo.go @@ -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 } diff --git a/proc_interrupts.go b/proc_interrupts.go index 643b500d..2a2412c4 100644 --- a/proc_interrupts.go +++ b/proc_interrupts.go @@ -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 } diff --git a/proc_io.go b/proc_io.go index dd8086ba..ca221bb6 100644 --- a/proc_io.go +++ b/proc_io.go @@ -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//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 } diff --git a/proc_netstat.go b/proc_netstat.go index b91423fc..6a118f58 100644 --- a/proc_netstat.go +++ b/proc_netstat.go @@ -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//net/netstat. @@ -185,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 } diff --git a/proc_psi.go b/proc_psi.go index cc2c5de8..5f0fbdff 100644 --- a/proc_psi.go +++ b/proc_psi.go @@ -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/. 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) } diff --git a/proc_smaps.go b/proc_smaps.go index f637309b..dff5cfb8 100644 --- a/proc_smaps.go +++ b/proc_smaps.go @@ -23,7 +23,7 @@ import ( "strconv" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) var ( @@ -60,7 +60,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() } diff --git a/proc_snmp.go b/proc_snmp.go index 8d9a9bcd..531bc837 100644 --- a/proc_snmp.go +++ b/proc_snmp.go @@ -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//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 } diff --git a/proc_snmp6.go b/proc_snmp6.go index 841fef46..8296a4ae 100644 --- a/proc_snmp6.go +++ b/proc_snmp6.go @@ -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//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. diff --git a/proc_stat.go b/proc_stat.go index 02e3f9e3..d9e544bc 100644 --- a/proc_stat.go +++ b/proc_stat.go @@ -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 } diff --git a/proc_statm.go b/proc_statm.go index 6bcc97ec..5fbe2796 100644 --- a/proc_statm.go +++ b/proc_statm.go @@ -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 } diff --git a/proc_status.go b/proc_status.go index 12d65581..8c1652e1 100644 --- a/proc_status.go +++ b/proc_status.go @@ -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 } diff --git a/proc_sys.go b/proc_sys.go index 52658a4d..c465b6be 100644 --- a/proc_sys.go +++ b/proc_sys.go @@ -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,7 +25,7 @@ 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 } @@ -41,7 +41,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) diff --git a/resctrlfs/info.go b/resctrlfs/info.go index 39e61645..2a85a1f9 100644 --- a/resctrlfs/info.go +++ b/resctrlfs/info.go @@ -18,7 +18,7 @@ package resctrlfs import ( "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const l3MonInfoPath = "info/L3_MON" @@ -43,13 +43,13 @@ type L3MonInfo struct { func (fs FS) L3MonInfo() (L3MonInfo, error) { var info L3MonInfo - numRMIDs, err := util.ReadUintFromFile(fs.resctrl.Path(l3MonInfoPath, "num_rmids")) + numRMIDs, err := parsers.ReadUintFromFile(fs.resctrl.Path(l3MonInfoPath, "num_rmids")) if err != nil { return info, err } info.NumRMIDs = numRMIDs - data, err := util.ReadFileNoStat(fs.resctrl.Path(l3MonInfoPath, "mon_features")) + data, err := parsers.ReadFileNoStat(fs.resctrl.Path(l3MonInfoPath, "mon_features")) if err != nil { return info, err } diff --git a/resctrlfs/mon_data.go b/resctrlfs/mon_data.go index 785bc7fa..c0676ef3 100644 --- a/resctrlfs/mon_data.go +++ b/resctrlfs/mon_data.go @@ -21,7 +21,7 @@ import ( "path/filepath" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const monDataPath = "mon_data" @@ -84,7 +84,7 @@ func (fs FS) MonData() ([]MonData, error) { // The kernel writes the literal "Unavailable" when the hardware can not // deliver a sample, which is a normal and transient state. func readCounter(domain, name string) *uint64 { - value, err := util.ReadUintFromFile(filepath.Join(domain, name)) + value, err := parsers.ReadUintFromFile(filepath.Join(domain, name)) if err != nil { return nil } diff --git a/slab.go b/slab.go index 32a04678..b78bac63 100644 --- a/slab.go +++ b/slab.go @@ -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 } diff --git a/softirqs.go b/softirqs.go index 47b73a72..dcd58593 100644 --- a/softirqs.go +++ b/softirqs.go @@ -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 } diff --git a/stat.go b/stat.go index 593ad0f6..781bd28a 100644 --- a/stat.go +++ b/stat.go @@ -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. @@ -167,7 +167,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 } diff --git a/swaps.go b/swaps.go index ee17bf48..8f9bbfb5 100644 --- a/swaps.go +++ b/swaps.go @@ -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 } diff --git a/sysfs/class_cooling_device.go b/sysfs/class_cooling_device.go index 037c333e..953c0239 100644 --- a/sysfs/class_cooling_device.go +++ b/sysfs/class_cooling_device.go @@ -20,7 +20,7 @@ import ( "strconv" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // ClassCoolingDeviceStats contains info from files in /sys/class/thermal/cooling_device[0-9]* @@ -59,12 +59,12 @@ func (fs FS) ClassCoolingDeviceStats() ([]ClassCoolingDeviceStats, error) { } func parseCoolingDeviceStats(cd string) (ClassCoolingDeviceStats, error) { - cdType, err := util.SysReadFile(filepath.Join(cd, "type")) + cdType, err := parsers.SysReadFile(filepath.Join(cd, "type")) if err != nil { return ClassCoolingDeviceStats{}, err } - cdMaxStateString, err := util.SysReadFile(filepath.Join(cd, "max_state")) + cdMaxStateString, err := parsers.SysReadFile(filepath.Join(cd, "max_state")) if err != nil { return ClassCoolingDeviceStats{}, err } @@ -75,7 +75,7 @@ func parseCoolingDeviceStats(cd string) (ClassCoolingDeviceStats, error) { // cur_state can be -1, eg intel powerclamp // https://www.kernel.org/doc/Documentation/thermal/intel_powerclamp.txt - cdCurStateString, err := util.SysReadFile(filepath.Join(cd, "cur_state")) + cdCurStateString, err := parsers.SysReadFile(filepath.Join(cd, "cur_state")) if err != nil { return ClassCoolingDeviceStats{}, err } diff --git a/sysfs/class_dmi.go b/sysfs/class_dmi.go index 3cdd95fa..397834cd 100644 --- a/sysfs/class_dmi.go +++ b/sysfs/class_dmi.go @@ -20,7 +20,7 @@ import ( "os" "path/filepath" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const dmiClassPath = "class/dmi/id" @@ -71,7 +71,7 @@ func (fs FS) DMIClass() (*DMIClass, error) { } filename := filepath.Join(path, name) - value, err := util.SysReadFile(filename) + value, err := parsers.SysReadFile(filename) if err != nil { if os.IsPermission(err) { // Only root is allowed to read the serial and product_uuid files! diff --git a/sysfs/class_drm.go b/sysfs/class_drm.go index c0ca599b..8d6e5f64 100644 --- a/sysfs/class_drm.go +++ b/sysfs/class_drm.go @@ -18,9 +18,9 @@ package sysfs import ( "path/filepath" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) func readDRMCardField(card, field string) (string, error) { - return util.SysReadFile(filepath.Join(card, "device", field)) + return parsers.SysReadFile(filepath.Join(card, "device", field)) } diff --git a/sysfs/class_drm_amdgpu.go b/sysfs/class_drm_amdgpu.go index 7ba4f6fc..bfd3f82b 100644 --- a/sysfs/class_drm_amdgpu.go +++ b/sysfs/class_drm_amdgpu.go @@ -23,7 +23,7 @@ import ( "strings" "syscall" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const ( @@ -89,7 +89,7 @@ func (fs FS) ClassDRMCardAMDGPUStats() ([]ClassDRMCardAMDGPUStats, error) { } func parseClassDRMAMDGPUCard(card string) (ClassDRMCardAMDGPUStats, error) { - uevent, err := util.SysReadFile(filepath.Join(card, "device/uevent")) + uevent, err := parsers.SysReadFile(filepath.Join(card, "device/uevent")) if err != nil { return ClassDRMCardAMDGPUStats{}, err } @@ -111,25 +111,25 @@ func parseClassDRMAMDGPUCard(card string) (ClassDRMCardAMDGPUStats, error) { return ClassDRMCardAMDGPUStats{}, err } if v, err := readDRMCardField(card, "gpu_busy_percent"); err == nil { - stats.GPUBusyPercent = *util.NewValueParser(v).PUInt64() + stats.GPUBusyPercent = *parsers.NewValueParser(v).PUInt64() } if v, err := readDRMCardField(card, "mem_info_gtt_total"); err == nil { - stats.MemoryGTTSize = *util.NewValueParser(v).PUInt64() + stats.MemoryGTTSize = *parsers.NewValueParser(v).PUInt64() } if v, err := readDRMCardField(card, "mem_info_gtt_used"); err == nil { - stats.MemoryGTTUsed = *util.NewValueParser(v).PUInt64() + stats.MemoryGTTUsed = *parsers.NewValueParser(v).PUInt64() } if v, err := readDRMCardField(card, "mem_info_vis_vram_total"); err == nil { - stats.MemoryVisibleVRAMSize = *util.NewValueParser(v).PUInt64() + stats.MemoryVisibleVRAMSize = *parsers.NewValueParser(v).PUInt64() } if v, err := readDRMCardField(card, "mem_info_vis_vram_used"); err == nil { - stats.MemoryVisibleVRAMUsed = *util.NewValueParser(v).PUInt64() + stats.MemoryVisibleVRAMUsed = *parsers.NewValueParser(v).PUInt64() } if v, err := readDRMCardField(card, "mem_info_vram_total"); err == nil { - stats.MemoryVRAMSize = *util.NewValueParser(v).PUInt64() + stats.MemoryVRAMSize = *parsers.NewValueParser(v).PUInt64() } if v, err := readDRMCardField(card, "mem_info_vram_used"); err == nil { - stats.MemoryVRAMUsed = *util.NewValueParser(v).PUInt64() + stats.MemoryVRAMUsed = *parsers.NewValueParser(v).PUInt64() } if v, err := readDRMCardField(card, "mem_info_vram_vendor"); err == nil { stats.MemoryVRAMVendor = v diff --git a/sysfs/class_drm_card.go b/sysfs/class_drm_card.go index 057634ec..aa382b8c 100644 --- a/sysfs/class_drm_card.go +++ b/sysfs/class_drm_card.go @@ -19,7 +19,7 @@ import ( "fmt" "path/filepath" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const drmClassPath = "class/drm" @@ -103,21 +103,21 @@ func (fs FS) parseDRMCard(name string) (*DRMCard, error) { } func parseDRMCardPort(port string) (*DRMCardPort, error) { - portStatus, err := util.SysReadFile(filepath.Join(port, "status")) + portStatus, err := parsers.SysReadFile(filepath.Join(port, "status")) if err != nil { return nil, err } drmCardPort := DRMCardPort{Name: filepath.Base(port), Status: portStatus} - portDPMS, err := util.SysReadFile(filepath.Join(port, "dpms")) + portDPMS, err := parsers.SysReadFile(filepath.Join(port, "dpms")) if err != nil { return nil, err } drmCardPort.DPMS = portDPMS - portEnabled, err := util.SysReadFile(filepath.Join(port, "enabled")) + portEnabled, err := parsers.SysReadFile(filepath.Join(port, "enabled")) if err != nil { return nil, err } diff --git a/sysfs/class_fibrechannel.go b/sysfs/class_fibrechannel.go index a7844f1e..cb8355da 100644 --- a/sysfs/class_fibrechannel.go +++ b/sysfs/class_fibrechannel.go @@ -21,7 +21,7 @@ import ( "os" "path/filepath" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const fibrechannelClassPath = "class/fc_host" @@ -90,7 +90,7 @@ func (fs FS) parseFibreChannelHost(name string) (*FibreChannelHost, error) { for _, f := range [...]string{"speed", "port_state", "port_type", "node_name", "port_id", "port_name", "fabric_name", "dev_loss_tmo", "symbolic_name", "supported_classes", "supported_speeds"} { name := filepath.Join(path, f) - value, err := util.SysReadFile(name) + value, err := parsers.SysReadFile(name) if err != nil { // drivers can choose not to expose some attributes to sysfs. // See: https://github.com/prometheus/node_exporter/issues/2919. @@ -166,7 +166,7 @@ func parseFibreChannelStatistics(hostPath string) (*FibreChannelCounters, error) } name := filepath.Join(path, f.Name()) - value, err := util.SysReadFile(name) + value, err := parsers.SysReadFile(name) if err != nil { // there are some write-only files in this directory; we can safely skip over them if os.IsNotExist(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) { @@ -175,7 +175,7 @@ func parseFibreChannelStatistics(hostPath string) (*FibreChannelCounters, error) return nil, fmt.Errorf("failed to read file %q: %w", name, err) } - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) // Below switch was automatically generated. Don't need everything in there yet, so the unwanted bits are commented out. switch f.Name() { diff --git a/sysfs/class_infiniband.go b/sysfs/class_infiniband.go index 4a893ae6..52f373b6 100644 --- a/sysfs/class_infiniband.go +++ b/sysfs/class_infiniband.go @@ -24,7 +24,7 @@ import ( "strings" "syscall" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const infinibandClassPath = "class/infiniband" @@ -166,7 +166,7 @@ func (fs FS) parseInfiniBandDevice(name string) (*InfiniBandDevice, error) { device := InfiniBandDevice{Name: name} // fw_ver is exposed by all InfiniBand drivers since kernel version 4.10. - value, err := util.SysReadFile(filepath.Join(path, "fw_ver")) + value, err := parsers.SysReadFile(filepath.Join(path, "fw_ver")) if err != nil { return nil, fmt.Errorf("failed to read HCA firmware version: %w", err) } @@ -175,7 +175,7 @@ func (fs FS) parseInfiniBandDevice(name string) (*InfiniBandDevice, error) { // Not all InfiniBand drivers expose all of these. for _, f := range [...]string{"board_id", "hca_type", "node_guid"} { name := filepath.Join(path, f) - value, err := util.SysReadFile(name) + value, err := parsers.SysReadFile(name) if err != nil { if os.IsNotExist(err) { continue @@ -331,7 +331,7 @@ func parseInfiniBandCounters(portPath string) (*InfiniBandCounters, error) { } name := filepath.Join(path, f.Name()) - value, err := util.SysReadFile(name) + value, err := parsers.SysReadFile(name) if err != nil { if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) || errors.Is(err, syscall.EINVAL) { continue @@ -345,7 +345,7 @@ func parseInfiniBandCounters(portPath string) (*InfiniBandCounters, error) { // Mellanox cards have 4 lanes per port, so all values must be multiplied by 4 // to get the expected value. - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) switch f.Name() { case "excessive_buffer_overrun_errors": @@ -426,7 +426,7 @@ func parseInfiniBandCounters(portPath string) (*InfiniBandCounters, error) { } name := filepath.Join(path, f.Name()) - value, err := util.SysReadFile(name) + value, err := parsers.SysReadFile(name) if err != nil { if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) { continue @@ -434,7 +434,7 @@ func parseInfiniBandCounters(portPath string) (*InfiniBandCounters, error) { return nil, fmt.Errorf("failed to read file %q: %w", name, err) } - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) switch f.Name() { case "port_multicast_rcv_packets": @@ -494,7 +494,7 @@ func parseInfiniBandHwCounters(portPath string) (*InfiniBandHwCounters, error) { } name := filepath.Join(path, f.Name()) - value, err := util.SysReadFile(name) + value, err := parsers.SysReadFile(name) if err != nil { if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) { continue @@ -502,7 +502,7 @@ func parseInfiniBandHwCounters(portPath string) (*InfiniBandHwCounters, error) { return nil, fmt.Errorf("failed to read file %q: %w", name, err) } - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) switch f.Name() { case "duplicate_request": diff --git a/sysfs/class_mei.go b/sysfs/class_mei.go index 93eee22f..ade3a2a5 100644 --- a/sysfs/class_mei.go +++ b/sysfs/class_mei.go @@ -20,7 +20,7 @@ import ( "os" "path/filepath" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const meiClassPath = "class/mei" @@ -82,7 +82,7 @@ func (fs FS) parseMEI(meiDev string) (MEIDev, error) { } filename := filepath.Join(path, name) - value, err := util.SysReadFile(filename) + value, err := parsers.SysReadFile(filename) if err != nil { if os.IsPermission(err) { continue diff --git a/sysfs/class_nvme.go b/sysfs/class_nvme.go index 7c3638a6..688fef8d 100644 --- a/sysfs/class_nvme.go +++ b/sysfs/class_nvme.go @@ -22,7 +22,7 @@ import ( "regexp" "strconv" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const nvmeClassPath = "class/nvme" @@ -87,7 +87,7 @@ func (fs FS) parseNVMeDevice(name string) (*NVMeDevice, error) { // Parse device-level attributes for _, f := range [...]string{"firmware_rev", "model", "serial", "state", "cntlid"} { name := filepath.Join(path, f) - value, err := util.SysReadFile(name) + value, err := parsers.SysReadFile(name) if err != nil { return nil, fmt.Errorf("failed to read file %q: %w", name, err) } @@ -132,7 +132,7 @@ func (fs FS) parseNVMeDevice(name string) (*NVMeDevice, error) { // Parse namespace attributes using the same approach as device attributes for _, f := range [...]string{"nuse", "size", "queue/logical_block_size", "ana_state"} { filePath := filepath.Join(namespacePath, f) - value, err := util.SysReadFile(filePath) + value, err := parsers.SysReadFile(filePath) if err != nil { if f == "ana_state" { // ana_state may not exist, skip silently diff --git a/sysfs/class_nvme_subsystem.go b/sysfs/class_nvme_subsystem.go index c222609b..99e00f84 100644 --- a/sysfs/class_nvme_subsystem.go +++ b/sysfs/class_nvme_subsystem.go @@ -21,7 +21,7 @@ import ( "regexp" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const nvmeSubsystemClassPath = "class/nvme-subsystem" @@ -105,7 +105,7 @@ func (fs FS) parseNVMeSubsystem(name string) (*NVMeSubsystem, error) { {"serial", &subsys.Serial}, {"iopolicy", &subsys.IOPolicy}, } { - val, err := util.SysReadFile(fs.sys.Path(nvmeSubsystemClassPath, name, attr.file)) + val, err := parsers.SysReadFile(fs.sys.Path(nvmeSubsystemClassPath, name, attr.file)) if err != nil { return nil, fmt.Errorf("failed to read %s for %s: %w", attr.file, name, err) } @@ -147,7 +147,7 @@ func (fs FS) parseNVMeSubsystemController(subsysName, ctrlName string) (*NVMeSub {"transport", &ctrl.Transport}, {"address", &ctrl.Address}, } { - val, err := util.SysReadFile(fs.sys.Path(nvmeSubsystemClassPath, subsysName, ctrlName, attr.file)) + val, err := parsers.SysReadFile(fs.sys.Path(nvmeSubsystemClassPath, subsysName, ctrlName, attr.file)) if err != nil { return nil, fmt.Errorf("failed to read %s for %s/%s: %w", attr.file, subsysName, ctrlName, err) } diff --git a/sysfs/class_power_supply.go b/sysfs/class_power_supply.go index 8a5e35f1..c4019797 100644 --- a/sysfs/class_power_supply.go +++ b/sysfs/class_power_supply.go @@ -21,7 +21,7 @@ import ( "os" "path/filepath" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // PowerSupply contains info from files in /sys/class/power_supply for a @@ -140,7 +140,7 @@ func parsePowerSupply(path string) (*PowerSupply, error) { } name := filepath.Join(path, f.Name()) - value, err := util.SysReadFile(name) + value, err := parsers.SysReadFile(name) if err != nil { if os.IsNotExist(err) || err.Error() == "operation not supported" || err.Error() == "no such device" || errors.Is(err, os.ErrInvalid) { continue @@ -148,7 +148,7 @@ func parsePowerSupply(path string) (*PowerSupply, error) { return nil, fmt.Errorf("failed to read file %q: %w", name, err) } - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) switch f.Name() { case "authentic": diff --git a/sysfs/class_powercap.go b/sysfs/class_powercap.go index 75b3c467..6c7f984b 100644 --- a/sysfs/class_powercap.go +++ b/sysfs/class_powercap.go @@ -22,7 +22,7 @@ import ( "strconv" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // RaplZone stores the information for one RAPL power zone. @@ -63,7 +63,7 @@ func GetRaplZones(fs FS) ([]RaplZone, error) { maxMicrojouleFilename := filepath.Join(raplDir, f.Name(), "/max_energy_range_uj") - maxMicrojoules, err := util.ReadUintFromFile(maxMicrojouleFilename) + maxMicrojoules, err := parsers.ReadUintFromFile(maxMicrojouleFilename) if err != nil { return nil, err } @@ -90,7 +90,7 @@ func GetRaplZones(fs FS) ([]RaplZone, error) { // GetEnergyMicrojoules returns the current microjoule value from the zone energy counter // https://www.kernel.org/doc/Documentation/power/powercap/powercap.txt func (rz RaplZone) GetEnergyMicrojoules() (uint64, error) { - return util.ReadUintFromFile(filepath.Join(rz.Path, "/energy_uj")) + return parsers.ReadUintFromFile(filepath.Join(rz.Path, "/energy_uj")) } // getIndexAndName returns a pair of (index, name) for a given name and name diff --git a/sysfs/class_sas_device.go b/sysfs/class_sas_device.go index bc4b242a..45c2ad98 100644 --- a/sysfs/class_sas_device.go +++ b/sysfs/class_sas_device.go @@ -21,7 +21,7 @@ import ( "regexp" "slices" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const ( @@ -111,7 +111,7 @@ func (fs FS) parseSASDevice(name string) (*SASDevice, error) { } address := fs.sys.Path(sasDeviceClassPath, name, "sas_address") - value, err := util.SysReadFile(address) + value, err := parsers.SysReadFile(address) if err != nil { return nil, err } diff --git a/sysfs/class_sas_phy.go b/sysfs/class_sas_phy.go index 7be976cf..9b21c6cc 100644 --- a/sysfs/class_sas_phy.go +++ b/sysfs/class_sas_phy.go @@ -24,7 +24,7 @@ import ( "strings" "syscall" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const sasPhyClassPath = "class/sas_phy" @@ -96,7 +96,7 @@ func (fs FS) parseSASPhy(name string) (*SASPhy, error) { name := filepath.Join(phypath, f.Name()) fileinfo, _ := os.Stat(name) if fileinfo.Mode().IsRegular() { - value, err := util.SysReadFile(name) + value, err := parsers.SysReadFile(name) if err != nil { if os.IsPermission(err) || errors.Is(err, syscall.EINVAL) { continue @@ -104,7 +104,7 @@ func (fs FS) parseSASPhy(name string) (*SASPhy, error) { return nil, fmt.Errorf("failed to read file %q: %w", name, err) } - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) switch f.Name() { case "sas_address": phy.SASAddress = value diff --git a/sysfs/class_scsitape.go b/sysfs/class_scsitape.go index 5cde0ead..390aa19a 100644 --- a/sysfs/class_scsitape.go +++ b/sysfs/class_scsitape.go @@ -21,7 +21,7 @@ import ( "path/filepath" "regexp" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const scsiTapeClassPath = "class/scsi_tape" @@ -101,12 +101,12 @@ func parseSCSITapeStatistics(tapePath string) (*SCSITapeCounters, error) { for _, f := range files { name := filepath.Join(path, f.Name()) - value, err := util.SysReadFile(name) + value, err := parsers.SysReadFile(name) if err != nil { return nil, fmt.Errorf("failed to read file %q: %w", name, err) } - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) switch f.Name() { case "in_flight": counters.InFlight = *vp.PUInt64() diff --git a/sysfs/class_thermal.go b/sysfs/class_thermal.go index 8372f137..4402b3d2 100644 --- a/sysfs/class_thermal.go +++ b/sysfs/class_thermal.go @@ -22,7 +22,7 @@ import ( "path/filepath" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // ClassThermalZoneStats contains info from files in /sys/class/thermal/thermal_zone @@ -59,28 +59,28 @@ func (fs FS) ClassThermalZoneStats() ([]ClassThermalZoneStats, error) { func parseClassThermalZone(zone string) ClassThermalZoneStats { var errs []error // Required attributes. - zoneType, err := util.SysReadFile(filepath.Join(zone, "type")) + zoneType, err := parsers.SysReadFile(filepath.Join(zone, "type")) if err != nil { errs = append(errs, fmt.Errorf("error reading type: %w", err)) } - zonePolicy, err := util.SysReadFile(filepath.Join(zone, "policy")) + zonePolicy, err := parsers.SysReadFile(filepath.Join(zone, "policy")) if err != nil { errs = append(errs, fmt.Errorf("error reading policy: %w", err)) } - zoneTemp, err := util.SysReadIntFromFile(filepath.Join(zone, "temp")) + zoneTemp, err := parsers.SysReadIntFromFile(filepath.Join(zone, "temp")) if err != nil && !errors.Is(err, os.ErrInvalid) { errs = append(errs, fmt.Errorf("error reading temp: %w", err)) } // Optional attributes. - mode, err := util.SysReadFile(filepath.Join(zone, "mode")) + mode, err := parsers.SysReadFile(filepath.Join(zone, "mode")) if err != nil && !os.IsNotExist(err) && !os.IsPermission(err) { errs = append(errs, fmt.Errorf("error reading mode: %w", err)) } - zoneMode := util.ParseBool(mode) + zoneMode := parsers.ParseBool(mode) var zonePassive *uint64 - passive, err := util.SysReadUintFromFile(filepath.Join(zone, "passive")) + passive, err := parsers.SysReadUintFromFile(filepath.Join(zone, "passive")) switch { case os.IsNotExist(err), os.IsPermission(err): zonePassive = nil diff --git a/sysfs/class_thermal_test.go b/sysfs/class_thermal_test.go index 0e5feeb0..f09c0219 100644 --- a/sysfs/class_thermal_test.go +++ b/sysfs/class_thermal_test.go @@ -20,7 +20,7 @@ import ( "github.com/google/go-cmp/cmp" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) func TestClassThermalZoneStats(t *testing.T) { @@ -34,7 +34,7 @@ func TestClassThermalZoneStats(t *testing.T) { t.Fatal(err) } - enabled := util.ParseBool("enabled") + enabled := parsers.ParseBool("enabled") passive := uint64(0) classThermalZoneStats := []ClassThermalZoneStats{ diff --git a/sysfs/class_watchdog.go b/sysfs/class_watchdog.go index 0062f0d6..c72bdf89 100644 --- a/sysfs/class_watchdog.go +++ b/sysfs/class_watchdog.go @@ -20,7 +20,7 @@ import ( "os" "path/filepath" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const watchdogClassPath = "class/watchdog" @@ -76,7 +76,7 @@ func (fs FS) parseWatchdog(wdName string) (*WatchdogStats, error) { for _, f := range [...]string{"bootstatus", "options", "fw_version", "identity", "nowayout", "state", "status", "timeleft", "timeout", "pretimeout", "pretimeout_governor", "access_cs0"} { name := filepath.Join(path, f) - value, err := util.SysReadFile(name) + value, err := parsers.SysReadFile(name) if err != nil { if os.IsNotExist(err) { continue @@ -84,7 +84,7 @@ func (fs FS) parseWatchdog(wdName string) (*WatchdogStats, error) { return nil, fmt.Errorf("failed to read file %q: %w", name, err) } - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) switch f { case "bootstatus": diff --git a/sysfs/clocksource.go b/sysfs/clocksource.go index ccb92d18..2359624a 100644 --- a/sysfs/clocksource.go +++ b/sysfs/clocksource.go @@ -19,7 +19,7 @@ import ( "path/filepath" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // ClockSource contains metrics related to the clock source. @@ -63,7 +63,7 @@ func parseClocksource(clocksourcePath string) (*ClockSource, error) { var err error for i, f := range stringFiles { - stringOut[i], err = util.SysReadFile(filepath.Join(clocksourcePath, f)) + stringOut[i], err = parsers.SysReadFile(filepath.Join(clocksourcePath, f)) if err != nil { return &ClockSource{}, err } diff --git a/sysfs/mdraid.go b/sysfs/mdraid.go index d706d216..2da4e051 100644 --- a/sysfs/mdraid.go +++ b/sysfs/mdraid.go @@ -22,7 +22,7 @@ import ( "strconv" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // Mdraid holds info parsed from relevant files in the /sys/block/md*/md directory. @@ -63,7 +63,7 @@ func (fs FS) Mdraids() ([]Mdraid, error) { md := Mdraid{Device: filepath.Base(filepath.Dir(m))} path := fs.sys.Path("block", md.Device, "md") - if val, err := util.SysReadFile(filepath.Join(path, "level")); err == nil { + if val, err := parsers.SysReadFile(filepath.Join(path, "level")); err == nil { md.Level = val } else { return mdraids, err @@ -71,13 +71,13 @@ func (fs FS) Mdraids() ([]Mdraid, error) { // Array state can be one of: clear, inactive, readonly, read-auto, clean, active, // write-pending, active-idle. - if val, err := util.SysReadFile(filepath.Join(path, "array_state")); err == nil { + if val, err := parsers.SysReadFile(filepath.Join(path, "array_state")); err == nil { md.ArrayState = val } else { return mdraids, err } - if val, err := util.SysReadFile(filepath.Join(path, "metadata_version")); err == nil { + if val, err := parsers.SysReadFile(filepath.Join(path, "metadata_version")); err == nil { md.MetadataVersion = val } else { return mdraids, err @@ -117,7 +117,7 @@ func (fs FS) Mdraids() ([]Mdraid, error) { // If neither format matches, Disks remains nil. } - if val, err := util.SysReadFile(filepath.Join(path, "uuid")); err == nil { + if val, err := parsers.SysReadFile(filepath.Join(path, "uuid")); err == nil { md.UUID = val } else { return mdraids, err @@ -129,7 +129,7 @@ func (fs FS) Mdraids() ([]Mdraid, error) { // Component state can be a comma-separated list of: faulty, in_sync, writemostly, // blocked, spare, write_error, want_replacement, replacement. - if val, err := util.SysReadFile(filepath.Join(dev, "state")); err == nil { + if val, err := parsers.SysReadFile(filepath.Join(dev, "state")); err == nil { comp.State = val } else { return mdraids, err @@ -143,7 +143,7 @@ func (fs FS) Mdraids() ([]Mdraid, error) { switch md.Level { case "raid0", "raid4", "raid5", "raid6", "raid10": - if val, err := util.ReadUintFromFile(filepath.Join(path, "chunk_size")); err == nil { + if val, err := parsers.ReadUintFromFile(filepath.Join(path, "chunk_size")); err == nil { md.ChunkSize = val } else { return mdraids, err @@ -152,20 +152,20 @@ func (fs FS) Mdraids() ([]Mdraid, error) { switch md.Level { case "raid1", "raid4", "raid5", "raid6", "raid10": - if val, err := util.ReadUintFromFile(filepath.Join(path, "degraded")); err == nil { + if val, err := parsers.ReadUintFromFile(filepath.Join(path, "degraded")); err == nil { md.DegradedDisks = val } else { return mdraids, err } // Array sync action can be one of: resync, recover, idle, check, repair. - if val, err := util.SysReadFile(filepath.Join(path, "sync_action")); err == nil { + if val, err := parsers.SysReadFile(filepath.Join(path, "sync_action")); err == nil { md.SyncAction = val } else { return mdraids, err } - if val, err := util.SysReadFile(filepath.Join(path, "sync_completed")); err == nil { + if val, err := parsers.SysReadFile(filepath.Join(path, "sync_completed")); err == nil { if val != "none" { var a, b uint64 diff --git a/sysfs/net_class.go b/sysfs/net_class.go index e97d0801..1f081d65 100644 --- a/sysfs/net_class.go +++ b/sysfs/net_class.go @@ -22,7 +22,7 @@ import ( "path/filepath" "syscall" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) const netclassPath = "class/net" @@ -157,7 +157,7 @@ func canIgnoreError(err error) bool { // It returns an error if the file cannot be read and the error is fatal. func ParseNetClassAttribute(devicePath, attrName string, interfaceClass *NetClassIface) error { attrPath := filepath.Join(devicePath, attrName) - value, err := util.SysReadFile(attrPath) + value, err := parsers.SysReadFile(attrPath) if err != nil { if canIgnoreError(err) { return nil @@ -165,7 +165,7 @@ func ParseNetClassAttribute(devicePath, attrName string, interfaceClass *NetClas return fmt.Errorf("failed to read file %q: %w", attrPath, err) } - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) switch attrName { case "addr_assign_type": interfaceClass.AddrAssignType = vp.PInt64() diff --git a/sysfs/net_class_aer.go b/sysfs/net_class_aer.go index 6bed0cab..872d34c8 100644 --- a/sysfs/net_class_aer.go +++ b/sysfs/net_class_aer.go @@ -21,7 +21,7 @@ import ( "strconv" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // CorrectableAerCounters contains values from /sys/class/net//device/aer_dev_correctable @@ -134,7 +134,7 @@ func parseAerCounters(devicePath string) (*AerCounters, error) { // /sys/class/net//device/aer_dev_correctable. func parseCorrectableAerCounters(devicePath string, counters *CorrectableAerCounters) error { path := filepath.Join(devicePath, "device", "aer_dev_correctable") - value, err := util.SysReadFile(path) + value, err := parsers.SysReadFile(path) if err != nil { if canIgnoreError(err) { return nil @@ -186,7 +186,7 @@ func parseCorrectableAerCounters(devicePath string, counters *CorrectableAerCoun func parseUncorrectableAerCounters(devicePath string, counterType string, counters *UncorrectableAerCounters) error { path := filepath.Join(devicePath, "device", "aer_dev_"+counterType) - value, err := util.ReadFileNoStat(path) + value, err := parsers.ReadFileNoStat(path) if err != nil { if canIgnoreError(err) { return nil diff --git a/sysfs/net_class_ecn.go b/sysfs/net_class_ecn.go index 69e6cfd1..24b1b2f5 100644 --- a/sysfs/net_class_ecn.go +++ b/sysfs/net_class_ecn.go @@ -21,7 +21,7 @@ import ( "path/filepath" "strconv" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // Documentation of the sysfs path @@ -221,7 +221,7 @@ func ParseRoceNpEcnInfo(ecnPath string, ecn *RoceNpEcn) error { // Parses all of the attributes in for ROCE NP protocol. func ParseRoceNpEcnAttribute(ecnPath string, attrName string, ecn *RoceNpEcn) error { attrPath := filepath.Join(ecnPath, attrName) - value, err := util.SysReadFile(attrPath) + value, err := parsers.SysReadFile(attrPath) if err != nil { if canIgnoreError(err) { return nil @@ -229,7 +229,7 @@ func ParseRoceNpEcnAttribute(ecnPath string, attrName string, ecn *RoceNpEcn) er return fmt.Errorf("failed to read file %q: %w", attrPath, err) } - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) switch attrName { case "min_time_between_cnps": ecn.MinTimeBetweenCnps = *vp.PUInt64() @@ -272,7 +272,7 @@ func ParseRoceRpEcnInfo(ecnPath string, ecn *RoceRpEcn) error { // Parses all of the attributes in for ROCE RP protocol. func ParseRoceRpEcnAttribute(ecnPath string, attrName string, ecn *RoceRpEcn) error { attrPath := filepath.Join(ecnPath, attrName) - value, err := util.SysReadFile(attrPath) + value, err := parsers.SysReadFile(attrPath) if err != nil { if canIgnoreError(err) { return nil @@ -280,7 +280,7 @@ func ParseRoceRpEcnAttribute(ecnPath string, attrName string, ecn *RoceRpEcn) er return fmt.Errorf("failed to read file %q: %w", attrPath, err) } - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) switch attrName { case "clamp_tgt_rate": switch *vp.PUInt64() { @@ -352,7 +352,7 @@ func ParseEcnEnable(path string) (map[uint8]bool, error) { continue } - value, err := util.SysReadFile(filepath.Join(path, filename)) + value, err := parsers.SysReadFile(filepath.Join(path, filename)) if err != nil { if canIgnoreError(err) { return nil, err @@ -360,7 +360,7 @@ func ParseEcnEnable(path string) (map[uint8]bool, error) { return nil, fmt.Errorf("failed to read file %q: %w", filename, err) } - vp := util.NewValueParser(value) + vp := parsers.NewValueParser(value) fileValue := *vp.PUInt64() switch fileValue { case 0: diff --git a/sysfs/pci_device.go b/sysfs/pci_device.go index aef87336..f66bf66b 100644 --- a/sysfs/pci_device.go +++ b/sysfs/pci_device.go @@ -22,7 +22,7 @@ import ( "strconv" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // PciPowerState represents the power state of a PCI device. @@ -220,7 +220,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) { // These files must exist in a device directory. for _, f := range [...]string{"class", "vendor", "device", "subsystem_vendor", "subsystem_device", "revision"} { name := filepath.Join(path, f) - valueStr, err := util.SysReadFile(name) + valueStr, err := parsers.SysReadFile(name) if err != nil { return nil, fmt.Errorf("failed to read file %q: %w", name, err) } @@ -249,7 +249,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) { for _, f := range [...]string{"max_link_speed", "max_link_width", "current_link_speed", "current_link_width", "numa_node"} { name := filepath.Join(path, f) - valueStr, err := util.SysReadFile(name) + valueStr, err := parsers.SysReadFile(name) if err != nil { if os.IsNotExist(err) { continue @@ -311,7 +311,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) { // Parse SR-IOV files (these are optional and may not exist for all devices) for _, f := range [...]string{"sriov_drivers_autoprobe", "sriov_numvfs", "sriov_offset", "sriov_stride", "sriov_totalvfs", "sriov_vf_device", "sriov_vf_total_msix"} { name := filepath.Join(path, f) - valueStr, err := util.SysReadFile(name) + valueStr, err := parsers.SysReadFile(name) if err != nil { if os.IsNotExist(err) { continue // SR-IOV files are optional @@ -387,7 +387,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) { // Parse power management files (these are optional and may not exist for all devices) for _, f := range [...]string{"d3cold_allowed", "power_state"} { name := filepath.Join(path, f) - valueStr, err := util.SysReadFile(name) + valueStr, err := parsers.SysReadFile(name) if err != nil { if os.IsNotExist(err) { continue // Power management files are optional diff --git a/sysfs/system_cpu.go b/sysfs/system_cpu.go index 12c5b0bb..0c827f7f 100644 --- a/sysfs/system_cpu.go +++ b/sysfs/system_cpu.go @@ -24,7 +24,7 @@ import ( "golang.org/x/sync/errgroup" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // CPU represents a path to a CPU located in `/sys/devices/system/cpu/cpu[0-9]*`. @@ -100,19 +100,19 @@ func (c CPU) Topology() (*CPUTopology, error) { func parseCPUTopology(cpuPath string) (*CPUTopology, error) { t := CPUTopology{} var err error - t.CoreID, err = util.SysReadFile(filepath.Join(cpuPath, "core_id")) + t.CoreID, err = parsers.SysReadFile(filepath.Join(cpuPath, "core_id")) if err != nil { return nil, err } - t.PhysicalPackageID, err = util.SysReadFile(filepath.Join(cpuPath, "physical_package_id")) + t.PhysicalPackageID, err = parsers.SysReadFile(filepath.Join(cpuPath, "physical_package_id")) if err != nil { return nil, err } - t.CoreSiblingsList, err = util.SysReadFile(filepath.Join(cpuPath, "core_siblings_list")) + t.CoreSiblingsList, err = parsers.SysReadFile(filepath.Join(cpuPath, "core_siblings_list")) if err != nil { return nil, err } - t.ThreadSiblingsList, err = util.SysReadFile(filepath.Join(cpuPath, "thread_siblings_list")) + t.ThreadSiblingsList, err = parsers.SysReadFile(filepath.Join(cpuPath, "thread_siblings_list")) if err != nil { return nil, err } @@ -135,7 +135,7 @@ func (c CPU) ThermalThrottle() (*CPUThermalThrottle, error) { // Online returns the online status of a CPU from `/sys/devices/system/cpu/cpuN/online`. func (c CPU) Online() (bool, error) { cpuPath := filepath.Join(string(c), "online") - str, err := util.SysReadFile(cpuPath) + str, err := parsers.SysReadFile(cpuPath) if err != nil { return false, err } @@ -145,11 +145,11 @@ func (c CPU) Online() (bool, error) { func parseCPUThermalThrottle(cpuPath string) (*CPUThermalThrottle, error) { t := CPUThermalThrottle{} var err error - t.PackageThrottleCount, err = util.ReadUintFromFile(filepath.Join(cpuPath, "package_throttle_count")) + t.PackageThrottleCount, err = parsers.ReadUintFromFile(filepath.Join(cpuPath, "package_throttle_count")) if err != nil { return nil, err } - t.CoreThrottleCount, err = util.ReadUintFromFile(filepath.Join(cpuPath, "core_throttle_count")) + t.CoreThrottleCount, err = parsers.ReadUintFromFile(filepath.Join(cpuPath, "core_throttle_count")) if err != nil { return nil, err } @@ -210,7 +210,7 @@ func (fs FS) SystemCpufreq() ([]SystemCPUCpufreqStats, error) { return nil, err } - line, err := util.ReadFileNoStat(fs.sys.Path("devices/system/cpu/offline")) + line, err := parsers.ReadFileNoStat(fs.sys.Path("devices/system/cpu/offline")) if err != nil { return nil, err } @@ -281,7 +281,7 @@ func parseCpufreqCpuinfo(cpuPath string) (*SystemCPUCpufreqStats, error) { uintOut := make([]*uint64, len(uintFiles)) for i, f := range uintFiles { - v, err := util.ReadUintFromFile(filepath.Join(cpuPath, f)) + v, err := parsers.ReadUintFromFile(filepath.Join(cpuPath, f)) if err != nil { if os.IsNotExist(err) || os.IsPermission(err) { continue @@ -303,7 +303,7 @@ func parseCpufreqCpuinfo(cpuPath string) (*SystemCPUCpufreqStats, error) { var err error for i, f := range stringFiles { - stringOut[i], err = util.SysReadFile(filepath.Join(cpuPath, f)) + stringOut[i], err = parsers.SysReadFile(filepath.Join(cpuPath, f)) if err != nil { return &SystemCPUCpufreqStats{}, err } @@ -311,7 +311,7 @@ func parseCpufreqCpuinfo(cpuPath string) (*SystemCPUCpufreqStats, error) { // "total_trans" is the total number of times the CPU has changed frequency. var cpuinfoFrequencyTransitionsTotal *uint64 - cpuinfoFrequencyTransitionsTotalUint, err := util.ReadUintFromFile(filepath.Join(cpuPath, "stats", "total_trans")) + cpuinfoFrequencyTransitionsTotalUint, err := parsers.ReadUintFromFile(filepath.Join(cpuPath, "stats", "total_trans")) if err != nil { if !os.IsNotExist(err) && !os.IsPermission(err) { return &SystemCPUCpufreqStats{}, err @@ -322,7 +322,7 @@ func parseCpufreqCpuinfo(cpuPath string) (*SystemCPUCpufreqStats, error) { // "time_in_state" is the total time spent at each frequency. var cpuinfoFrequencyDuration *map[uint64]uint64 - cpuinfoFrequencyDurationString, err := util.ReadFileNoStat(filepath.Join(cpuPath, "stats", "time_in_state")) + cpuinfoFrequencyDurationString, err := parsers.ReadFileNoStat(filepath.Join(cpuPath, "stats", "time_in_state")) if err != nil { if !os.IsNotExist(err) && !os.IsPermission(err) { return &SystemCPUCpufreqStats{}, err @@ -351,7 +351,7 @@ func parseCpufreqCpuinfo(cpuPath string) (*SystemCPUCpufreqStats, error) { // "trans_table" contains information about all the CPU frequency transitions. var cpuinfoTransitionTable *[][]uint64 - cpuinfoTransitionTableString, err := util.ReadFileNoStat(filepath.Join(cpuPath, "stats", "trans_table")) + cpuinfoTransitionTableString, err := parsers.ReadFileNoStat(filepath.Join(cpuPath, "stats", "trans_table")) if err != nil { if !os.IsNotExist(err) && !os.IsPermission(err) { return &SystemCPUCpufreqStats{}, err diff --git a/sysfs/vmstat_numa.go b/sysfs/vmstat_numa.go index bf2153a5..dca28b5b 100644 --- a/sysfs/vmstat_numa.go +++ b/sysfs/vmstat_numa.go @@ -24,7 +24,7 @@ import ( "strconv" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) var ( @@ -106,7 +106,7 @@ func (fs FS) VMStatNUMA() (map[int]VMStat, error) { if err != nil { return nil, err } - file, err := util.ReadFileNoStat(filepath.Join(node, "vmstat")) + file, err := parsers.ReadFileNoStat(filepath.Join(node, "vmstat")) if err != nil { return nil, err } diff --git a/vm.go b/vm.go index 52180c03..62725b42 100644 --- a/vm.go +++ b/vm.go @@ -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 diff --git a/xfs/parse.go b/xfs/parse.go index c8a55339..f0b1d88e 100644 --- a/xfs/parse.go +++ b/xfs/parse.go @@ -19,7 +19,7 @@ import ( "io" "strings" - "github.com/prometheus/procfs/internal/util" + "github.com/prometheus/procfs/internal/parsers" ) // ParseStats parses a Stats from an input io.Reader, using the format @@ -78,7 +78,7 @@ func ParseStats(r io.Reader) (*Stats, error) { // Special case: "gc xpc" is a two-word label in the kernel output. if label == "gc" && len(ss) >= 3 && ss[1] == "xpc" { - us, err := util.ParseUint64s(ss[2:]) + us, err := parsers.ParseUint64s(ss[2:]) if err != nil { return nil, err } @@ -91,7 +91,7 @@ func ParseStats(r io.Reader) (*Stats, error) { // Extended precision counters are uint64 values. if label == fieldXpc { - us, err := util.ParseUint64s(ss[1:]) + us, err := parsers.ParseUint64s(ss[1:]) if err != nil { return nil, err } @@ -106,7 +106,7 @@ func ParseStats(r io.Reader) (*Stats, error) { // Defer relog counter is a single uint64 value. if label == fieldDeferRelog { - us, err := util.ParseUint64s(ss[1:]) + us, err := parsers.ParseUint64s(ss[1:]) if err != nil { return nil, err } @@ -118,7 +118,7 @@ func ParseStats(r io.Reader) (*Stats, error) { } // All other counters are uint32 values. - us, err := util.ParseUint32s(ss[1:]) + us, err := parsers.ParseUint32s(ss[1:]) if err != nil { return nil, err } diff --git a/zoneinfo.go b/zoneinfo.go index 63d1898b..71b3c2b6 100644 --- a/zoneinfo.go +++ b/zoneinfo.go @@ -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. @@ -103,7 +103,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 +179,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 }