Repolode
shirou

shirou/gopsutil

A Go port of psutil for reading system information such as CPU, memory, disk, network, and process stats across platforms.

Stars
11,938
Forks
1,691
Open issues
219
Last commit
3 days ago

What is it?

gopsutil is a Go library that exposes system metrics and process information through a single API, modeled on the Python psutil library. It lets Go programs query CPU times and usage, virtual and swap memory, disk partitions and usage, network I/O counters, connections, host and boot information, users, and per-process details such as memory, CPU, and open files.

The library covers Linux, FreeBSD, OpenBSD, macOS (Darwin), Windows, and Solaris on several architectures, with partial support for DragonFly BSD and Linux RISC-V. It is implemented without cgo by porting the relevant C structs to Go, so it can be built and cross-compiled with the standard toolchain. Platform-specific details are available through `Ex` structs such as `ExLinux` and `ExWindows`.

The project uses calendar versioning (vMAJOR.YY.MM) and requires Go 1.18 or later. Several Linux-only helpers are included for Docker container CPU and memory cgroup stats and netfilter conntrack counters. Directory paths such as /proc and /sys can be redirected with environment variables or a context value.

Key features

  • 01Cross-platform CPU, memory, disk, and network metrics through one Go API
  • 02Per-process information such as memory, CPU, open files, and connections
  • 03No cgo dependency; C structs are ported to Go
  • 04Platform-specific extras via Ex structs such as ExLinux and ExWindows
  • 05Configurable system paths for containers or alternate mount points

Use cases

  • Building monitoring agents or exporters that report host metrics in Go
  • Writing CLI tools that show system status across Linux, macOS, and Windows
  • Collecting per-process resource usage for diagnostics or dashboards
  • Reading Docker container cgroup stats from inside a Linux host

Quick start

  1. 1

    Install the library into your Go module

    go get github.com/shirou/gopsutil/v4
  2. 2

    Import a package such as mem and read system memory stats in your code

Things to know

  • Requires Go 1.18 or above.
  • Platform support varies; some functions are partial or broken on certain operating systems.

Topics

FAQ

What is gopsutil?
A Go port of psutil for reading system information such as CPU, memory, disk, network, and process stats across platforms. gopsutil is a Go library that exposes system metrics and process information through a single API, modeled on the Python psutil library. It lets Go programs query CPU times and usage, virtual and swap memory, disk partitions and usage, network I/O counters, connections, host and boot information, users, and per-process details such as memory, CPU, and open files.
Is gopsutil free to use? What license does it have?
gopsutil is open source under the Other license. Check the license terms before using it in commercial products.
Is gopsutil still maintained?
Actively maintained. The last commit to gopsutil was on Nov 5, 2026.
What can I use gopsutil for?
Building monitoring agents or exporters that report host metrics in Go Writing CLI tools that show system status across Linux, macOS, and Windows Collecting per-process resource usage for diagnostics or dashboards Reading Docker container cgroup stats from inside a Linux host
How do I install gopsutil?
Install the library into your Go module: go get github.com/shirou/gopsutil/v4 Import a package such as mem and read system memory stats in your code
Where can I get gopsutil?
The source code and installation instructions are on GitHub: https://github.com/shirou/gopsutil

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects