Created
February 8, 2016 13:54
-
-
Save josdirksen/f2462dcaebd9d43e37b6 to your computer and use it in GitHub Desktop.
Revisions
-
josdirksen created this gist
Feb 8, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ package handlers import ( "net/http" "fmt" "bytes" "github.com/shirou/gopsutil/mem" "github.com/shirou/gopsutil/host" "io" ) type SystemHandler struct { } func NewSystemHandler() *SystemHandler { p := new(SystemHandler) return p } func (sh SystemHandler) HandleCommand(cmdToExecute *Command, w http.ResponseWriter) { switch cmdToExecute.SlackCommand { case "mem" : handleMemCommand(w) case "host" : handleHostCommand(w) } } func handleHostCommand(w http.ResponseWriter) { var buffer bytes.Buffer info, _ := host.HostInfo() buffer.WriteString(fmt.Sprintf("Boottime: %v\n", info.BootTime)) buffer.WriteString(fmt.Sprintf("Hostname: %v\n", info.Hostname)) buffer.WriteString(fmt.Sprintf("Uptime: %v\n", info.Uptime)) io.WriteString(w, buffer.String()) } func handleMemCommand(w http.ResponseWriter) { v, _ := mem.VirtualMemory() var buffer bytes.Buffer buffer.WriteString(fmt.Sprintf(fmt.Sprintf("Total: %v, Free:%v, UsedPercent:%f\n", v.Total, v.Free, v.UsedPercent))) io.WriteString(w, buffer.String()) }