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.

README.md 2.8 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # procfs
  2. This package provides functions to retrieve system, kernel, and process
  3. metrics from the pseudo-filesystems /proc and /sys.
  4. *WARNING*: This package is a work in progress. Its API may still break in
  5. backwards-incompatible ways without warnings. Use it at your own risk.
  6. [![Go Reference](https://pkg.go.dev/badge/github.com/prometheus/procfs.svg)](https://pkg.go.dev/github.com/prometheus/procfs)
  7. [![CircleCI](https://circleci.com/gh/prometheus/procfs/tree/master.svg?style=svg)](https://circleci.com/gh/prometheus/procfs/tree/master)
  8. [![Go Report Card](https://goreportcard.com/badge/github.com/prometheus/procfs)](https://goreportcard.com/report/github.com/prometheus/procfs)
  9. ## Usage
  10. The procfs library is organized by packages based on whether the gathered data is coming from
  11. /proc, /sys, or both. Each package contains an `FS` type which represents the path to either /proc,
  12. /sys, or both. For example, cpu statistics are gathered from
  13. `/proc/stat` and are available via the root procfs package. First, the proc filesystem mount
  14. point is initialized, and then the stat information is read.
  15. ```go
  16. fs, err := procfs.NewFS("/proc")
  17. stats, err := fs.Stat()
  18. ```
  19. Some sub-packages such as `blockdevice`, require access to both the proc and sys filesystems.
  20. ```go
  21. fs, err := blockdevice.NewFS("/proc", "/sys")
  22. stats, err := fs.ProcDiskstats()
  23. ```
  24. ## Package Organization
  25. The packages in this project are organized according to (1) whether the data comes from the `/proc` or
  26. `/sys` filesystem and (2) the type of information being retrieved. For example, most process information
  27. can be gathered from the functions in the root `procfs` package. Information about block devices such as disk drives
  28. is available in the `blockdevices` sub-package.
  29. ## Building and Testing
  30. The procfs library is intended to be built as part of another application, so there are no distributable binaries.
  31. However, most of the API includes unit tests which can be run with `make test`.
  32. ### Updating Test Fixtures
  33. The procfs library includes a set of test fixtures which include many example files from
  34. the `/proc` and `/sys` filesystems. These fixtures are included as a [ttar](https://github.com/ideaship/ttar) file
  35. which is extracted automatically during testing. To add/update the test fixtures, first
  36. ensure the `fixtures` directory is up to date by removing the existing directory and then
  37. extracting the ttar file using `make fixtures/.unpacked` or just `make test`.
  38. ```bash
  39. rm -rf fixtures
  40. make test
  41. ```
  42. Next, make the required changes to the extracted files in the `fixtures` directory. When
  43. the changes are complete, run `make update_fixtures` to create a new `fixtures.ttar` file
  44. based on the updated `fixtures` directory. And finally, verify the changes using
  45. `git diff fixtures.ttar`.