Created
July 20, 2018 01:58
-
-
Save benyanke/3cc0b064943843dc858a8f25e7091913 to your computer and use it in GitHub Desktop.
Proof of concept for a system stats monitor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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