Skip to content

Instantly share code, notes, and snippets.

@benyanke
Created July 20, 2018 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benyanke/3cc0b064943843dc858a8f25e7091913 to your computer and use it in GitHub Desktop.
Save benyanke/3cc0b064943843dc858a8f25e7091913 to your computer and use it in GitHub Desktop.
Proof of concept for a system stats monitor
package main
import (
"fmt"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/load"
"github.com/shirou/gopsutil/mem"
)
func main() {
v, _ := mem.VirtualMemory()
h, _ := host.Info()
l, _ := load.Avg()
c, _ := cpu.Times(true)
// almost every return value is a struct
fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
// convert to JSON. String() is also implemented
fmt.Println(v.UsedPercent)
// convert to JSON. String() is also implemented
fmt.Println(h)
fmt.Println(l)
fmt.Println(c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment