v0.7.2
Fix data types for ignored stat fields #401

Some ignored fields in the /proc/[pid]/stat file may have values that are bigger than the max value of the current Go type that is used for the ignored variable. That leads to issues in runtime on some systems that use the maximum possible values for the related fields.

See for details:
* https://man7.org/linux/man-pages/man5/proc.5.html
* https://man7.org/linux/man-pages/man3/scanf.3.html

Signed-off-by: Vyacheslav Kulakov <kulakov.home@gmail.com>
2 files changed
tree: 8e0f1a3ab92026413ae729e83475db8e2dfbc48d
  1. .circleci/
  2. bcache/
  3. blockdevice/
  4. btrfs/
  5. internal/
  6. iscsi/
  7. nfs/
  8. scripts/
  9. sysfs/
  10. xfs/
  11. .gitignore
  12. .golangci.yml
  13. arp.go
  14. arp_test.go
  15. buddyinfo.go
  16. buddyinfo_test.go
  17. cmdline.go
  18. cmdline_test.go
  19. CODE_OF_CONDUCT.md
  20. CONTRIBUTING.md
  21. cpuinfo.go
  22. cpuinfo_armx.go
  23. cpuinfo_mipsx.go
  24. cpuinfo_others.go
  25. cpuinfo_ppcx.go
  26. cpuinfo_riscvx.go
  27. cpuinfo_s390x.go
  28. cpuinfo_test.go
  29. cpuinfo_x86.go
  30. crypto.go
  31. crypto_test.go
  32. doc.go
  33. fixtures.ttar
  34. fs.go
  35. fs_test.go
  36. fscache.go
  37. fscache_test.go
  38. go.mod
  39. go.sum
  40. ipvs.go
  41. ipvs_test.go
  42. kernel_random.go
  43. kernel_random_test.go
  44. LICENSE
  45. loadavg.go
  46. loadavg_test.go
  47. MAINTAINERS.md
  48. Makefile
  49. Makefile.common
  50. mdstat.go
  51. mdstat_test.go
  52. meminfo.go
  53. meminfo_test.go
  54. mountinfo.go
  55. mountinfo_test.go
  56. mountstats.go
  57. mountstats_test.go
  58. net_conntrackstat.go
  59. net_conntrackstat_test.go
  60. net_dev.go
  61. net_dev_test.go
  62. net_ip_socket.go
  63. net_ip_socket_test.go
  64. net_protocols.go
  65. net_protocols_test.go
  66. net_sockstat.go
  67. net_sockstat_test.go
  68. net_softnet.go
  69. net_softnet_test.go
  70. net_tcp.go
  71. net_tcp_test.go
  72. net_udp.go
  73. net_udp_test.go
  74. net_unix.go
  75. net_unix_test.go
  76. NOTICE
  77. proc.go
  78. proc_cgroup.go
  79. proc_cgroup_test.go
  80. proc_environ.go
  81. proc_environ_test.go
  82. proc_fdinfo.go
  83. proc_fdinfo_test.go
  84. proc_io.go
  85. proc_io_test.go
  86. proc_limits.go
  87. proc_limits_test.go
  88. proc_maps.go
  89. proc_maps32_test.go
  90. proc_maps64_test.go
  91. proc_ns.go
  92. proc_ns_test.go
  93. proc_psi.go
  94. proc_psi_test.go
  95. proc_smaps.go
  96. proc_smaps_test.go
  97. proc_stat.go
  98. proc_stat_test.go
  99. proc_status.go
  100. proc_status_test.go
  101. proc_test.go
  102. README.md
  103. schedstat.go
  104. schedstat_test.go
  105. SECURITY.md
  106. slab.go
  107. slab_test.go
  108. stat.go
  109. stat_test.go
  110. swaps.go
  111. swaps_test.go
  112. ttar
  113. vm.go
  114. vm_test.go
  115. xfrm.go
  116. xfrm_test.go
  117. zoneinfo.go
  118. zoneinfo_test.go
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.

Go Reference CircleCI 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.