gopsutil ports psutil-style APIs to Go without cgo. It reads CPU, memory, disk, network, host, and process statistics across many operating systems.
Overview
gopsutil is a Go library that exposes operating-system and process metrics similar to the Python psutil project. Implementations translate platform C structures into Go so collectors can run on Linux, Windows, macOS, FreeBSD, OpenBSD, Solaris, and partial support on additional systems.
Packages cover CPU times and utilization, virtual memory and swap, disk partitions and I/O, network counters, boot time, logged-in users, process lists, and per-process details such as command line, memory maps, threads, and signals. Linux-only extras include Docker cgroup helpers, network protocol SNMP stats, and netfilter conntrack counts.
Callers can override paths to proc, sys, and related filesystem roots with environment variables or context values. Optional caching flags exist for boot time and related host data but may return stale values if the underlying counters change. Platform-specific Ex structs expose extra fields where generic APIs cannot cover OS differences.
The API is versioned with monthly tags and aims for backward compatibility within major releases. Documentation is published alongside the module for each subsystem.
Key features
- CPU, memory, disk, and network stats
- Process listing and per-PID inspection
- Host metadata and uptime
- Configurable proc and sys paths
- Pure Go without cgo
- Linux Docker cgroup helpers
- Optional metric caching
- Platform-specific Ex extensions
Use cases
- Monitoring agents written in Go
- Collecting machine metrics for dashboards
- Inspecting running processes programmatically
- Cross-platform ops tooling
- Container-aware resource reporting on Linux