explaingit

shirou/gopsutil

11,825GoAudience · developerComplexity · 2/5Setup · easy

TLDR

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.

Mindmap

mindmap
  root((gopsutil))
    What it does
      System metrics
      Process info
      Network counters
    Metric categories
      CPU usage
      Memory stats
      Disk space
      Network traffic
    Tech Stack
      Go
      No C code
    Platform support
      Linux macOS Windows
      BSD variants
    Use Cases
      Monitoring tools
      Health checks
      Resource logging
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a system monitoring tool in Go that periodically reads CPU and memory stats and displays them in a terminal or web dashboard.

USE CASE 2

Add a health-check endpoint to a Go service that reports available disk space and memory before accepting a job.

USE CASE 3

Collect per-process CPU and memory stats in a Go program to log resource usage of specific services over time.

USE CASE 4

Read network interface counters inside a container by pointing the library at a custom /proc path via an environment variable.

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

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.

Copy-paste prompts

Prompt 1
Write a Go program using gopsutil that prints a live-updating table of CPU percent, used memory, and disk usage for / every 2 seconds.
Prompt 2
Use gopsutil to list all running processes in Go and filter to those using more than 10% CPU, printing their PID and command name.
Prompt 3
Show me how to use gopsutil's net package in Go to read bytes sent and received per network interface and calculate throughput over a 1-second interval.
Prompt 4
Write a Go HTTP health-check handler that returns JSON with current memory usage and free disk space using gopsutil.
Prompt 5
How do I configure gopsutil to read /proc from a custom path inside a Docker container, and which environment variable controls this?
Open on GitHub → Explain another repo

← shirou on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.