Documentation ¶
Overview ¶
Package prc provides a set of functions to interact with system-related information exposed through the /proc filesystem.
This package is designed to work on Linux-based systems.
Install ¶
To use this module in your Go project, simply run:
go get -u git.sr.ht/~nzv/prc
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cmdline ¶
Cmdline reads kernel command-line parameters from the /proc/cmdline file and returns them as a slice of strings.
Example ¶
package main import ( "fmt" "log" "git.sr.ht/~nzv/prc" ) func main() { params, err := prc.Cmdline() if err != nil { log.Fatal(err) } // Print kernel command-line parameters fmt.Printf("Kernel Command Line Parameters:\n") for _, param := range params { fmt.Printf("%s\n", param) } }
Output:
Types ¶
type ProcCPUStats ¶
type ProcCPUStats struct { User uint64 // User mode CPU time Nice uint64 // Niced (priority-adjusted) user mode CPU time System uint64 // Kernel mode CPU time Idle uint64 // Idle CPU time IOWait uint64 // I/O wait time (complex interpretation) IRQ uint64 // Hardware interrupt servicing time SoftIRQ uint64 // Software interrupt (softirq) servicing time Steal uint64 // Involuntary wait time (e.g., virtualized) Guest uint64 // Normal guest CPU time GuestNice uint64 // Niced guest CPU time }
ProcCPUStats represents CPU usage statistics for various modes.
type ProcPartition ¶
type ProcPartition struct { Major uint // Major number of the partition. Minor uint // Minor number of the partition. Blocks uint64 // Total blocks in the partition. Name string // Name of the partition. }
ProcPartition represents disk partition information including major and minor numbers, block count, and name.
func Partitions ¶
func Partitions() ([]ProcPartition, error)
Partitions parses /proc/partitions for disk partition information and returns a slice of ProcPartition.
Example ¶
package main import ( "fmt" "log" "git.sr.ht/~nzv/prc" ) func main() { partitions, err := prc.Partitions() if err != nil { log.Fatal(err) } // Print information about disk partitions for _, partition := range partitions { fmt.Printf("Device: %s\n", partition.Name) fmt.Printf("Major: %d\n", partition.Major) fmt.Printf("Minor: %d\n", partition.Minor) fmt.Printf("Blocks: %d\n", partition.Blocks) } }
Output:
type ProcStat ¶
type ProcStat struct { CPU map[string]ProcCPUStats // CPU usage statistics per core Intr []uint64 // Interrupt counts since boot ContextSwitch uint64 // Total context switches BootTime uint64 // System boot time (Unix epoch) Processes uint64 // Total processes/threads created ProcsRunning uint64 // Runnable threads count ProcsBlocked uint64 // Blocked processes count SoftIRQ []uint64 // SoftIRQ counts since boot }
ProcStat represents system statistics including CPU usage, interrupt counts, context switches, boot time, process/thread counts, and softirq counts.
func Stat ¶
Stat parses /proc/stat for system statistics and returns a ProcStat struct.
Example ¶
package main import ( "fmt" "log" "git.sr.ht/~nzv/prc" ) func main() { stats, err := prc.Stat() if err != nil { log.Fatal(err) } // Print CPU usage statistics for all cores for core, cpuStats := range stats.CPU { fmt.Printf("CPU Core %s:\n", core) fmt.Printf("User: %d\n", cpuStats.User) fmt.Printf("System: %d\n", cpuStats.System) fmt.Printf("Idle: %d\n", cpuStats.Idle) // Add more fields as needed } // Print other system statistics fmt.Printf("Intr: %v\n", stats.Intr) fmt.Printf("Context Switches: %d\n", stats.ContextSwitch) fmt.Printf("Boot Time: %d\n", stats.BootTime) fmt.Printf("Processes: %d\n", stats.Processes) fmt.Printf("Processes Running: %d\n", stats.ProcsRunning) fmt.Printf("Processes Blocked: %d\n", stats.ProcsBlocked) fmt.Printf("SoftIRQ: %v\n", stats.SoftIRQ) }
Output:
type ProcUptime ¶
type ProcUptime struct { Boot time.Duration // System boot time Idle time.Duration // System idle time }
ProcUptime represents system boot time and idle time as time.Duration values.
func Uptime ¶
func Uptime() (*ProcUptime, error)
Uptime parses /proc/uptime and returns system boot time and idle time as time.Duration values in a ProcUptime struct.
Example ¶
package main import ( "fmt" "log" "git.sr.ht/~nzv/prc" ) func main() { uptime, err := prc.Uptime() if err != nil { log.Fatal(err) } fmt.Printf("System Uptime: %s\n", uptime.Boot) fmt.Printf("Idle Time: %s\n", uptime.Idle) }
Output:
type ProcVersion ¶
type ProcVersion struct { Release string // Kernel version GCC string // Compiler information Version string // Build kernel release BuildHost []string // Information about the build host: [user, hostname] }
ProcVersion represents information about the Linux kernel version.
func Version ¶
func Version() (*ProcVersion, error)
Version parses /proc/version and extracts information about the Linux kernel version.
Example ¶
package main import ( "fmt" "log" "git.sr.ht/~nzv/prc" ) func main() { version, err := prc.Version() if err != nil { log.Fatal(err) } // Print version information fmt.Println("Kernel Release:", version.Release) fmt.Println("GCC Version:", version.GCC) fmt.Println("Build Version:", version.Version) fmt.Println("Build Host User:", version.BuildHost[0]) fmt.Println("Build Host Hostname:", version.BuildHost[1]) }
Output: