procfs provides functions to retrieve system, kernel and process metrics from the pseudo-filesystem proc.
  • Go 98.8%
  • Shell 1.1%
Find a file
KBS 98e16a1603
netstat: check the scanner result and error (#868)
parseNetstat discards the first Scan result and never calls Err, so a
scanner failure is invisible. The loop then returns netStat, nil with
whatever was parsed before the failure, and the caller cannot tell a
short read from a complete one.

The header case is worse than a lost error. After Scan reports false
for a too-long token, the next Scan returns true with the bytes already
buffered, so headers stays empty while the counter loop runs, and
headers[num] panics with index out of range.

net_dev.go, net_sockstat.go, net_unix.go and stat.go all end their scan
with scanner.Err(); this is the outlier.

Signed-off-by: manon <youdie006@users.noreply.github.com>
Co-authored-by: manon <youdie006@users.noreply.github.com>
Co-authored-by: Ben Kochie <superq@gmail.com>
History 2026-10-22 14:58:39 +02:00
.github Improve linting (#865) 2026-10-17 12:19:29 +02:00
bcache Improve linting (#865) 2026-10-17 12:19:29 +02:00
bcachefs Improve linting (#865) 2026-10-17 12:19:29 +02:00
blockdevice Improve linting (#865) 2026-10-17 12:19:29 +02:00
btrfs Improve linting (#865) 2026-10-17 12:19:29 +02:00
ext4 Improve linting (#865) 2026-10-17 12:19:29 +02:00
internal Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
iscsi Improve linting (#865) 2026-10-17 12:19:29 +02:00
nfs Improve linting (#865) 2026-10-17 12:19:29 +02:00
resctrlfs Improve linting (#865) 2026-10-17 12:19:29 +02:00
scripts Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
selinuxfs Improve linting (#865) 2026-10-17 12:19:29 +02:00
sysfs sysfs: read NVMe namespace nuse on demand (#889) 2026-10-22 11:59:31 +02:00
testdata sysfs: read NVMe namespace nuse on demand (#889) 2026-10-22 11:59:31 +02:00
xfs Improve linting (#865) 2026-10-17 12:19:29 +02:00
.gitignore Move fixtures to testdata folder (#447) 2022-06-07 15:42:46 +02:00
.golangci.yml Improve linting (#865) 2026-10-17 12:19:29 +02:00
arp.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
arp_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
buddyinfo.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
buddyinfo_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
cmdline.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
cmdline_test.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
CODE_OF_CONDUCT.md Update common Prometheus files 2022-05-06 12:59:40 +02:00
CONTRIBUTING.md Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
cpuinfo.go cpuinfo: parse arm64 CPU implementer, variant, and part (#882) 2026-10-19 16:54:52 +02:00
cpuinfo_armx.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
cpuinfo_loong64.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
cpuinfo_mipsx.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
cpuinfo_others.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
cpuinfo_ppcx.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
cpuinfo_riscvx.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
cpuinfo_s390x.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
cpuinfo_test.go cpuinfo: parse arm64 CPU implementer, variant, and part (#882) 2026-10-19 16:54:52 +02:00
cpuinfo_x86.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
crypto.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
crypto_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
doc.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
fs.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
fs_statfs_notype.go isRealProc should return false on notype architectures (#853) 2026-08-28 15:50:18 +02:00
fs_statfs_type.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
fs_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
fscache.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
fscache_test.go chore: Migrate tests to cmp package (#760) 2025-10-27 08:28:30 +01:00
go.mod Improve linting (#865) 2026-10-17 12:19:29 +02:00
go.sum Improve linting (#865) 2026-10-17 12:19:29 +02:00
ipvs.go Return errors instead of panicking on short lines in meminfo, ipvs and cpufreq parsers (#880) 2026-10-21 08:41:36 +02:00
ipvs_test.go Return errors instead of panicking on short lines in meminfo, ipvs and cpufreq parsers (#880) 2026-10-21 08:41:36 +02:00
kernel_hung.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
kernel_hung_test.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
kernel_random.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
kernel_random_test.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
kernel_tainted.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
kernel_tainted_test.go kernel_tainted: use linux build tag instead of !windows (#847) 2026-07-17 09:04:24 +02:00
LICENSE License cleanup 2015-01-22 17:16:39 +01:00
loadavg.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
loadavg_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
MAINTAINERS.md update MAINTAINERS.md (#629) 2024-04-09 23:45:43 +02:00
Makefile [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
Makefile.common Update common Prometheus files (#867) 2026-10-10 08:53:19 +02:00
mdstat.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
mdstat_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
meminfo.go Return errors instead of panicking on short lines in meminfo, ipvs and cpufreq parsers (#880) 2026-10-21 08:41:36 +02:00
meminfo_test.go Return errors instead of panicking on short lines in meminfo, ipvs and cpufreq parsers (#880) 2026-10-21 08:41:36 +02:00
mountinfo.go Fix WSL2 mountinfo parsing (#874) 2026-10-19 16:33:59 +02:00
mountinfo_readfull_test.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
mountinfo_test.go Fix WSL2 mountinfo parsing (#874) 2026-10-19 16:33:59 +02:00
mountstats.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
mountstats_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
net_conntrackstat.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
net_conntrackstat_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
net_dev.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
net_dev_snmp6.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
net_dev_snmp6_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
net_dev_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
net_ip_socket.go fix(procfs): report raw values in parse errors (#841) 2026-07-17 09:21:47 +02:00
net_ip_socket_test.go fix(procfs): report raw values in parse errors (#841) 2026-07-17 09:21:47 +02:00
net_protocols.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
net_protocols_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
net_route.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
net_route_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
net_sockstat.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
net_sockstat_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
net_softnet.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
net_softnet_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
net_tcp.go Synchronize common files from prometheus/prometheus (#766) 2026-01-05 11:16:29 +01:00
net_tcp_test.go chore: Migrate tests to cmp package (#760) 2025-10-27 08:28:30 +01:00
net_tls_stat.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
net_tls_stat_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
net_udp.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
net_udp_test.go chore: Migrate tests to cmp package (#760) 2025-10-27 08:28:30 +01:00
net_unix.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
net_unix_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
net_wireless.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
net_wireless_test.go chore: Migrate tests to cmp package (#760) 2025-10-27 08:28:30 +01:00
net_xfrm.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
net_xfrm_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
netstat.go netstat: check the scanner result and error (#868) 2026-10-22 14:58:39 +02:00
netstat_test.go netstat: check the scanner result and error (#868) 2026-10-22 14:58:39 +02:00
nfnetlink_queue.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
nfnetlink_queue_test.go chore: Migrate tests to cmp package (#760) 2025-10-27 08:28:30 +01:00
NOTICE License cleanup 2015-01-22 17:16:39 +01:00
proc.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
proc_cgroup.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
proc_cgroup_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_cgroups.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
proc_cgroups_test.go chore: Migrate tests to cmp package (#760) 2025-10-27 08:28:30 +01:00
proc_environ.go preserve the final environment entry without a trailing NUL (#884) 2026-10-19 15:05:03 +02:00
proc_environ_test.go preserve the final environment entry without a trailing NUL (#884) 2026-10-19 15:05:03 +02:00
proc_fdinfo.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
proc_fdinfo_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
proc_interrupts.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
proc_interrupts_test.go chore: Migrate tests to cmp package (#760) 2025-10-27 08:28:30 +01:00
proc_io.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
proc_io_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
proc_limits.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_limits_test.go Fix Proc.Limits limit name matching (#667) 2025-10-21 14:13:43 +02:00
proc_maps.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_maps32_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_maps64_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_netstat.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
proc_netstat_test.go netstat: model legacy TcpExt counters removed from recent kernels (#863) 2026-08-27 12:20:36 +02:00
proc_ns.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
proc_ns_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
proc_psi.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_psi_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_smaps.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_smaps_test.go Synchronize common files from prometheus/prometheus (#747) 2025-11-18 13:25:26 +01:00
proc_snmp.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
proc_snmp6.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
proc_snmp6_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_snmp_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_stat.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
proc_stat_limits32_test.go test: split proc stat limit coverage by architecture (#833) 2026-10-22 11:55:51 +02:00
proc_stat_limits64_test.go test: split proc stat limit coverage by architecture (#833) 2026-10-22 11:55:51 +02:00
proc_stat_limits_test.go test: split proc stat limit coverage by architecture (#833) 2026-10-22 11:55:51 +02:00
proc_stat_test.go test: split proc stat limit coverage by architecture (#833) 2026-10-22 11:55:51 +02:00
proc_statm.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
proc_statm_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
proc_status.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_status_test.go feat: parse capabilities in /proc/pid/status (#784) 2026-02-25 11:55:47 +01:00
proc_sys.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
proc_sys_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
proc_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
README.md Cleanup CI 2026-04-02 08:08:16 +02:00
schedstat.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
schedstat_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
SECURITY.md Update common Prometheus files (#806) 2026-04-12 20:42:44 +02:00
slab.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
slab_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
softirqs.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
softirqs_test.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
stat.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
stat_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
swaps.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
swaps_test.go chore: Migrate tests to cmp package (#760) 2025-10-27 08:28:30 +01:00
thread.go [PROM-50] Update copyright headers (#756) 2025-10-20 13:33:24 +02:00
thread_test.go chore: Migrate tests to cmp package (#760) 2025-10-27 08:28:30 +01:00
ttar update vendored ttar 2019-05-16 14:44:56 -05:00
vm.go Rename internal/util package (#864) 2026-08-28 09:19:08 +02:00
vm_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
zoneinfo.go Improve linting (#865) 2026-10-17 12:19:29 +02:00
zoneinfo_test.go Improve linting (#865) 2026-10-17 12:19:29 +02:00

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.

Go Reference 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 testdata/fixtures directory is up to date by removing the existing directory and then extracting the ttar file using make testdata/fixtures/.unpacked or just make test.

rm -rf testdata/fixtures
make test

Next, make the required changes to the extracted files in the testdata/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 testdata/fixtures.ttar.