You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Brad Beam 8a05559602 feat: Add support for meminfo 6 days ago
.circleci enable codespell 5 months ago
bcache remove top level constructor functions 5 months ago
blockdevice remove top level constructor functions 5 months ago
btrfs Add tests and fixtures for Btrfs 4 weeks ago
internal move ReadFileNoStat to its own file 1 month ago
iscsi Add sysfs handle and remove path from Get backstore function 4 months ago
nfs remove top level constructor functions 5 months ago
scripts Add license check tool 1 year ago
sysfs powercap sysfs reader 3 weeks ago
xfs Collect additional XFS statistics 2 months ago
.gitignore Package fixtures directory using ttar 1 year ago
.golangci.yml Synchronize Makefile.common from prometheus/prometheus (#152) 6 months ago
CONTRIBUTING.md introduce new function ReadFileNoStat 1 month ago
LICENSE License cleanup 4 years ago
MAINTAINERS.md Make @pgier a maintainer (#155) 6 months ago
Makefile echoes when extracting fixtures 6 months ago
Makefile.common makefile: update Makefile.common with newer version 5 months ago
NOTICE License cleanup 4 years ago
README.md update readme and contributing guide 1 month ago
arp.go define constants outside of loop 2 months ago
arp_test.go rebase Initial support for parsing /proc/net/arp #105 from @skottler 2 months ago
buddyinfo.go fixing a few golint warnings 2 months ago
buddyinfo_test.go remove top level constructor functions 5 months ago
cpuinfo.go introduce new function ReadFileNoStat 1 month ago
cpuinfo_test.go use string type for ID fields and float64 for CPU MHz 2 months ago
crypto.go Add support for parsing /proc/crypto 3 months ago
crypto_test.go Add support for parsing /proc/crypto 3 months ago
doc.go Update example 4 years ago
fixtures.ttar feat: Add support for meminfo 1 day ago
fs.go remove top level constructor functions 5 months ago
fs_test.go Improved error message in getProcFixtures() 4 months ago
go.mod update go module dependencies 1 month ago
go.sum update go module dependencies 1 month ago
ipvs.go introduce new function ReadFileNoStat 1 month ago
ipvs_test.go remove top level constructor functions 5 months ago
mdstat.go Minor refactorings: 4 months ago
mdstat_test.go Minor refactorings: 4 months ago
meminfo.go feat: Add support for meminfo 1 day ago
meminfo_test.go feat: Add support for meminfo 1 day ago
mountinfo.go Update mountinfo parsing (#228) 4 days ago
mountinfo_test.go Update mountinfo parsing (#228) 4 days ago
mountstats.go Fix overflow in mounstats 5 months ago
mountstats_test.go remove top level constructor functions 5 months ago
net_dev.go Fix: RxPackets is doubled in package procfs (#226) 3 weeks ago
net_dev_test.go remove top level constructor functions 5 months ago
net_softnet.go Fix copyright lines. 2 months ago
net_softnet_test.go Fix copyright lines. 2 months ago
net_unix.go better kernel ptr format error msg for net/unix parser 5 months ago
net_unix_test.go remove unused import from net_unix_test 5 months ago
proc.go Update mountinfo parsing (#228) 4 days ago
proc_environ.go introduce new function ReadFileNoStat 1 month ago
proc_environ_test.go update fixtures for proc environ 4 months ago
proc_fdinfo.go introduce new function ReadFileNoStat 1 month ago
proc_fdinfo_test.go Parse fdinfo and inotify stats from /proc/[pid]/fdinfo/[fd] (#115) 4 months ago
proc_io.go introduce new function ReadFileNoStat 1 month ago
proc_io_test.go remove top level constructor functions 5 months ago
proc_limits.go re-add functions required by client_golang 5 months ago
proc_limits_test.go remove top level constructor functions 5 months ago
proc_ns.go remove top level constructor functions 5 months ago
proc_ns_test.go remove top level constructor functions 5 months ago
proc_psi.go introduce new function ReadFileNoStat 1 month ago
proc_psi_test.go remove top level constructor functions 5 months ago
proc_stat.go introduce new function ReadFileNoStat 1 month ago
proc_stat_test.go remove top level constructor functions 5 months ago
proc_status.go introduce new function ReadFileNoStat 1 month ago
proc_status_test.go Add ProcStatus.TGID 2 months ago
proc_test.go Parse fdinfo and inotify stats from /proc/[pid]/fdinfo/[fd] (#115) 4 months ago
schedstat.go fixing a few golint warnings 2 months ago
schedstat_test.go Fix seconds reported by schedstat 3 months ago
stat.go Convert stat parser to ReadFileNoStat() (#231) 5 days ago
stat_test.go remove top level constructor functions 5 months ago
ttar update vendored ttar 6 months ago
vm.go Change vm to use *int64 instead of int64 in struct fields 3 months ago
vm_test.go Change vm to use *int64 instead of int64 in struct fields 3 months ago
xfrm.go Use FS struct for proc and sys mount points in submodules (#149) 6 months ago
xfrm_test.go Use FS struct for proc and sys mount points in submodules (#149) 6 months ago
zoneinfo.go address review on !195 3 months ago
zoneinfo_test.go remove duplicate test util function 3 months ago

README.md

procfs

This package provides functions to retrieve system, kernel, and process metrics from the pseudo-filesystems /proc and /sys.

WARNING: This package is a work in progress. Its API may still break in backwards-incompatible ways without warnings. Use it at your own risk.

GoDoc Build Status Go Report Card

Usage

The procfs library is organized by packages based on whether the gathered data is coming from /proc, /sys, or both. Each package contains an FS type which represents the path to either /proc, /sys, or both. For example, cpu statistics are gathered from /proc/stat and are available via the root procfs package. First, the proc filesystem mount point is initialized, and then the stat information is read.

fs, err := procfs.NewFS("/proc")
stats, err := fs.Stat()

Some sub-packages such as blockdevice, require access to both the proc and sys filesystems.

    fs, err := blockdevice.NewFS("/proc", "/sys")
    stats, err := fs.ProcDiskstats()

Package Organization

The packages in this project are organized according to (1) whether the data comes from the /proc or /sys filesystem and (2) the type of information being retrieved. For example, most process information can be gathered from the functions in the root procfs package. Information about block devices such as disk drives is available in the blockdevices sub-package.

Building and Testing

The procfs library is intended to be built as part of another application, so there are no distributable binaries.
However, most of the API includes unit tests which can be run with make test.

Updating Test Fixtures

The procfs library includes a set of test fixtures which include many example files from the /proc and /sys filesystems. These fixtures are included as a ttar file which is extracted automatically during testing. To add/update the test fixtures, first ensure the fixtures directory is up to date by removing the existing directory and then extracting the ttar file using make fixtures/.unpacked or just make test.

rm -rf fixtures
make test

Next, make the required changes to the extracted files in the fixtures directory. When the changes are complete, run make update_fixtures to create a new fixtures.ttar file based on the updated fixtures directory. And finally, verify the changes using git diff fixtures.ttar.