Skip to main content

Overview

gopsutil provides robust support for Windows operating systems with native implementations for most system monitoring features. The library supports multiple architectures including traditional x86/x64 and modern ARM processors.

Supported Architectures

i386

32-bit x86 processors

amd64

64-bit x86-64 processors (most common)

arm

32-bit ARM processors

arm64

64-bit ARM processors (Windows on ARM)
Windows on ARM (arm64) support makes gopsutil compatible with modern ARM-based Windows devices.

Feature Support

Fully Supported Features

CPU Metrics

  • cpu.Times() - CPU time statistics
  • cpu.Count() - Number of logical and physical CPUs
  • cpu.Percent() - CPU utilization percentage
  • cpu.TimesPercent() - Per-CPU time percentages
  • cpu.Info() - Detailed CPU information:
    • VendorID
    • Family, Model, Stepping
    • ModelName
    • Number of cores
    • CPU frequency

Memory Metrics

  • mem.VirtualMemory() - Physical memory statistics
  • Platform-specific extended information via ExWindows (see below)
mem.SwapMemory() is not supported on Windows as the platform uses a different virtual memory model.

Disk Metrics

  • disk.Partitions() - List all disk partitions
  • disk.Usage() - Disk usage statistics per partition
  • disk.IOCounters() - I/O statistics for disk drives

Network Metrics

  • net.IOCounters() - Network interface statistics
The following network features are not supported on Windows:
  • net.Connections() - Active network connections
  • net.ProtoCounters() - Protocol-level statistics

System Information

  • host.Info() - Host information:
    • Hostname
    • OS (“windows”)
    • Platform version (e.g., “Windows 10”, “Windows 11”, “Windows Server 2019”)
  • host.BootTime() - System boot time
  • host.Users() - Currently logged-in users
Some host information fields like PlatformFamily are not available on Windows.

Load Average

import "github.com/shirou/gopsutil/v4/load"

avg, err := load.Avg()
fmt.Printf("Load averages: %.2f %.2f %.2f\n", avg.Load1, avg.Load5, avg.Load15)
Load average is calculated differently on Windows than on Unix systems, but the API remains consistent.

Temperature Sensors

import "github.com/shirou/gopsutil/v4/sensors"

temps, err := sensors.TemperaturesWithContext(ctx)
Windows supports temperature sensor reading through WMI.

Process Information

Windows provides good process monitoring support:

Supported Process Features

  • Basic: pid, ppid, name, cmdline, create_time, cwd
  • Executable: exe (executable path)
  • Resources: memory_info, memory_percent, cpu_times, cpu_percent
  • I/O: io_counters, open_files, num_fds
  • Priority: nice (process priority)
  • Threads: num_threads
  • Relations: parent, children
  • Control: suspend, resume, terminate
  • User: username
  • Stats: page_faults

Unsupported Process Features

  • status (process state)
  • uids/gids (Unix-specific)
  • terminal (Unix-specific)
  • num_ctx_switches (context switches)
  • memory_maps
  • send_signal (Unix signals)
  • kill (use terminate instead)
  • rlimit (Unix resource limits)
  • threads (detailed thread info)
  • connections (per-process network connections)

Platform-Specific Information (ExWindows)

Windows provides extended virtual memory information through the ExWindows struct:
import "github.com/shirou/gopsutil/v4/mem"

ex := mem.NewExWindows()
v, err := ex.VirtualMemory()
if err != nil {
    panic(err)
}

// Access Windows-specific virtual memory fields
fmt.Println("Virtual Total:", v.VirtualTotal)
fmt.Println("Virtual Available:", v.VirtualAvail)
fmt.Println("Virtual Used:", v.VirtualUsed)
fmt.Println("Virtual Used Percent:", v.VirtualUsedPercent)

Windows Virtual Memory Model

Windows uses a different memory management model compared to Unix systems:
  • VirtualTotal: Total virtual memory available to processes
  • VirtualAvail: Available virtual memory
  • VirtualUsed: Currently used virtual memory
  • VirtualUsedPercent: Percentage of virtual memory in use
This information is obtained through Windows-specific APIs and provides insight into the system’s virtual address space usage.
See the Platform-Specific Information page for more details on Ex structs.

Windows-Specific Considerations

WMI (Windows Management Instrumentation)

Many gopsutil functions on Windows use WMI to retrieve system information. This means:
  • WMI service must be running
  • Appropriate permissions are required
  • Performance may vary based on WMI query complexity

Administrator Privileges

Some operations may require elevated privileges:
import "github.com/shirou/gopsutil/v4/process"

// May require administrator privileges
p, err := process.NewProcess(1234)
if err != nil {
    log.Printf("Failed to access process: %v", err)
}

Process Termination

On Windows, use Terminate() instead of Kill():
p, _ := process.NewProcess(pid)

// Graceful termination
err := p.Terminate()

// Force termination (not available, use Terminate)
// err := p.Kill()  // Not supported on Windows

Path Separators

Windows uses backslashes (\) as path separators:
info, err := disk.Usage("C:\\")
if err != nil {
    log.Fatal(err)
}
Or use forward slashes (Go handles conversion):
info, err := disk.Usage("C:/")

Known Limitations

Swap Memory

mem.SwapMemory() is not supported on Windows. Use ExWindows to access virtual memory information instead.

Network Connections

Per-system and per-process network connection tracking is not currently supported:
// Not supported on Windows
conns, err := net.Connections("tcp")
// Returns error

Process Status

The process Status() method is not available on Windows:
p, _ := process.NewProcess(pid)
// status, err := p.Status()  // Not supported

Unix-Specific Features

The following Unix concepts don’t apply to Windows:
  • UIDs/GIDs (use Windows SIDs instead)
  • Terminals (PTY/TTY)
  • Unix signals
  • Resource limits (rlimit)

Performance Considerations

WMI Query Performance

WMI queries can be slow. Consider caching values when appropriate:
  • CPU information typically doesn’t change
  • Boot time remains constant
  • System information is static

Context Timeouts

import (
    "context"
    "time"
    "github.com/shirou/gopsutil/v4/cpu"
)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

info, err := cpu.InfoWithContext(ctx)
if err != nil {
    log.Printf("CPU info query timed out: %v", err)
}

Code Examples

Basic System Monitoring

package main

import (
    "fmt"
    "github.com/shirou/gopsutil/v4/cpu"
    "github.com/shirou/gopsutil/v4/disk"
    "github.com/shirou/gopsutil/v4/mem"
    "time"
)

func main() {
    // CPU usage
    percent, _ := cpu.Percent(time.Second, false)
    fmt.Printf("CPU Usage: %.2f%%\n", percent[0])
    
    // Memory info
    vmem, _ := mem.VirtualMemory()
    fmt.Printf("Memory: %.2f%% used\n", vmem.UsedPercent)
    
    // Disk usage for C: drive
    usage, _ := disk.Usage("C:/")
    fmt.Printf("Disk C: %.2f%% used\n", usage.UsedPercent)
}

Windows-Specific Virtual Memory

package main

import (
    "fmt"
    "github.com/shirou/gopsutil/v4/mem"
)

func main() {
    // Get standard memory info
    vmem, _ := mem.VirtualMemory()
    fmt.Printf("Physical Memory: %d MB\n", vmem.Total/1024/1024)
    
    // Get Windows-specific virtual memory info
    ex := mem.NewExWindows()
    exMem, _ := ex.VirtualMemory()
    
    fmt.Printf("Virtual Memory Total: %d MB\n", exMem.VirtualTotal/1024/1024)
    fmt.Printf("Virtual Memory Available: %d MB\n", exMem.VirtualAvail/1024/1024)
    fmt.Printf("Virtual Memory Used: %.2f%%\n", exMem.VirtualUsedPercent)
}

Process Monitoring

package main

import (
    "fmt"
    "github.com/shirou/gopsutil/v4/process"
)

func main() {
    // Get all processes
    processes, _ := process.Processes()
    
    for _, p := range processes {
        name, _ := p.Name()
        cpuPercent, _ := p.CPUPercent()
        memInfo, _ := p.MemoryInfo()
        
        fmt.Printf("PID: %d, Name: %s, CPU: %.2f%%, Memory: %d MB\n",
            p.Pid, name, cpuPercent, memInfo.RSS/1024/1024)
    }
}

Best Practices

Handle Platform Differences

import "runtime"

if runtime.GOOS == "windows" {
    // Windows-specific code
    ex := mem.NewExWindows()
    vmem, err := ex.VirtualMemory()
    // ...
} else {
    // Unix-like systems
    swap, err := mem.SwapMemory()
    // ...
}

Error Handling for Unsupported Features

conns, err := net.Connections("tcp")
if err != nil {
    if runtime.GOOS == "windows" {
        log.Println("Network connections not supported on Windows")
        return
    }
    log.Fatal(err)
}

Use Context for Long Operations

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

processes, err := process.ProcessesWithContext(ctx)
if err != nil {
    log.Printf("Failed to get processes: %v", err)
}

Platform Overview

Compare Windows support with other platforms

Platform-Specific

Learn about ExWindows structs

Build docs developers (and LLMs) love