host-stat-go is a Go module for collecting host stat.
This module provided functions to collect cpu/mem/disk/io/load/uptime/kernel info of the host.
Work for popular LINUX distributions ONLY
go get -u github.com/likexian/host-stat-go
import (
"github.com/likexian/host-stat-go"
)
Visit the docs on GoDoc
Get the memory stat
memStat, err := hoststat.GetMemStat()
if err == nil {
// print total memory of host in KB
fmt.Println(memStat.MemTotal)
// print used memory of host in KB
fmt.Println(memStat.MemUsed)
// print free memory of host in KB
fmt.Println(memStat.MemFree)
// print used memory rate of host in percent
fmt.Println(memStat.MemRate)
}
Copyright 2014-2019 Li Kexian
Licensed under the Apache License 2.0