Skip to main content
The host package provides functions to retrieve system-level host information including hostname, uptime, boot time, platform details, and currently logged-in users.

Key Features

System Information

Retrieve comprehensive host information including OS, platform, kernel version, and virtualization details

Boot Time & Uptime

Get system boot time and uptime with optional caching

User Sessions

Query currently logged-in users and their session information

Platform Detection

Detect OS platform, family, and version information

Core Types

InfoStat

The primary struct containing comprehensive host information:
type InfoStat struct {
    Hostname             string `json:"hostname"`
    Uptime               uint64 `json:"uptime"`
    BootTime             uint64 `json:"bootTime"`
    Procs                uint64 `json:"procs"`           // number of processes
    OS                   string `json:"os"`              // ex: freebsd, linux
    Platform             string `json:"platform"`        // ex: ubuntu, linuxmint
    PlatformFamily       string `json:"platformFamily"`  // ex: debian, rhel
    PlatformVersion      string `json:"platformVersion"` // version of the complete OS
    KernelVersion        string `json:"kernelVersion"`   // version of the OS kernel
    KernelArch           string `json:"kernelArch"`      // native cpu architecture
    VirtualizationSystem string `json:"virtualizationSystem"`
    VirtualizationRole   string `json:"virtualizationRole"` // guest or host
    HostID               string `json:"hostId"`             // ex: uuid
}

UserStat

Represents a logged-in user session:
type UserStat struct {
    User     string `json:"user"`
    Terminal string `json:"terminal"`
    Host     string `json:"host"`
    Started  int    `json:"started"`
}

Main Functions

Info()

Get comprehensive host information

BootTime()

Get system boot time in seconds since epoch

Users()

Get list of currently logged-in users

PlatformInformation()

Get platform, family, and version information

Quick Start

package main

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

func main() {
    // Get host information
    info, err := host.Info()
    if err != nil {
        panic(err)
    }
    
    fmt.Printf("Hostname: %s\n", info.Hostname)
    fmt.Printf("OS: %s\n", info.OS)
    fmt.Printf("Platform: %s\n", info.Platform)
    fmt.Printf("Uptime: %d seconds\n", info.Uptime)
}

Context Support

All functions have context-aware variants with the WithContext suffix, allowing for cancellation and timeout control:
  • InfoWithContext(ctx context.Context)
  • BootTimeWithContext(ctx context.Context)
  • UsersWithContext(ctx context.Context)
  • PlatformInformationWithContext(ctx context.Context)

Next Steps

Host Info

Learn about retrieving detailed host information

Boot Time

Understand boot time and uptime retrieval

Build docs developers (and LLMs) love