gopsutil
psutil for golang
A Go library for reading system metrics, CPU usage, memory, disk space, network traffic, and running processes, from a Go program. Works on Linux, macOS, Windows, and BSD systems with no C code required.
gopsutil is a Go library that lets programs read system information such as CPU usage, memory consumption, disk space, network traffic, and running processes. It is a port of the well-known Python library psutil, bringing the same kind of system monitoring capabilities to Go programs.
The library is organized into separate packages by category. For example, the mem package returns virtual memory statistics, the cpu package returns processor usage and clock speed information, and the net package returns network interface counters. Functions typically return structured data that can be inspected field by field or printed as JSON.
gopsutil works across multiple operating systems and hardware architectures. Full support covers Linux, macOS, Windows, FreeBSD, OpenBSD, and Solaris. Support for some metrics varies by platform: for example, Docker container statistics are Linux-only, and network I/O counters have partial support on macOS. The library is implemented entirely in Go without any C code, which simplifies cross-compilation.
For container-friendly configuration, the library reads system paths like /proc and /sys from environment variables, so you can point it at a different root if the process is running inside a container or accessing a remote filesystem. Caching of certain values such as boot time is available but off by default, since cached values can become stale. Platform-specific information not available on all operating systems is exposed through separate structs rather than being mixed into the common API.
Go 1.18 or newer is required. The library follows calendar-based versioning: the version number encodes the release year and month rather than arbitrary feature increments. Documentation is available at pkg.go.dev.
Where it fits
- Build a system monitoring tool in Go that periodically reads CPU and memory stats and displays them in a terminal or web dashboard.
- Add a health-check endpoint to a Go service that reports available disk space and memory before accepting a job.
- Collect per-process CPU and memory stats in a Go program to log resource usage of specific services over time.
- Read network interface counters inside a container by pointing the library at a custom /proc path via an environment variable.