Go module to get linux system stats.
Provides following information on systems:
- System
- Returns OS, Hostname, Kernel, Up time, last boot date, timezone, logged in users list
- CPU
- CPU model, freq, load average (overall, per core), etc
- Memory/SWAP
- Disks
- File system, type, mount point, usage, inodes
- Networks
- Interface, IP, Rx/Tx
- Service status
- Returns if given service is active or not
- Processes
- Returns list of processes sorted by CPU/Memory usage (with PID, exec path, user, usage)
Import the module
import ( "github.com/dhamith93/systats" ) func main() { syStats := systats.New() }
And use the methods to get the required and supported system stats.
Returns OS, Hostname, Kernel, Up time, last boot date, timezone, logged in users list
func main() { syStats := systats.New() system, err := systats.GetSystem() }
CPU info and load avg info (overall, and per core)
func main() { syStats := systats.New() cpu, err := systats.GetCPU() }
func main() { syStats := systats.New() memory, err := systats.GetMemory(systats.Megabyte) }
func main() { syStats := systats.New() swap, err := systats.GetSwap(systats.Megabyte) }
func main() { syStats := systats.New() disks, err := syStats.GetDisks() }
Interface info and usage info
func main() { syStats := systats.New() networks, err := syStats.GetNetworks() }
Returns if service is running or not
func main() { syStats := systats.New() running := syStats.IsServiceRunning(service) if !running { fmt.Println(service + " not running") } }
Returns running processes sorted by CPU or memory usage
func main() { syStats := systats.New() procs, err := syStats.GetTopProcesses(10, "cpu") procs, err := syStats.GetTopProcesses(10, "memory") }