Created
September 18, 2012 10:03
-
-
Save border/3742368 to your computer and use it in GitHub Desktop.
monitormem.go
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" | |
"syscall" | |
"time" | |
) | |
const ( | |
Megabyte = 1024 * 1024 | |
) | |
func main() { | |
var sysinfo syscall.Sysinfo_t | |
syscall.Sysinfo(&sysinfo) | |
mins := fmt.Sprintf("%ds", sysinfo.Uptime) | |
d, _ := time.ParseDuration(mins) | |
days := int64(d.Hours()) / 24 | |
min := int64(d.Minutes()) % 60 | |
sec := int64(d.Seconds()) % 60 | |
fmt.Printf("System Uptime: %d days, %02d:%02d\n", days, min, sec) | |
fmt.Printf("TotalMem: %d MB\n", sysinfo.Totalram/Megabyte) | |
fmt.Printf("FreeMem: %d MB\n", sysinfo.Freeram/Megabyte) | |
fmt.Printf("SharedMem: %d MB\n", sysinfo.Sharedram/Megabyte) | |
fmt.Printf("BufferMem: %d MB\n", sysinfo.Bufferram/Megabyte) | |
fmt.Printf("Totalswap: %d MB\n", sysinfo.Totalswap/Megabyte) | |
fmt.Printf("Freeswap: %d MB\n", sysinfo.Freeswap/Megabyte) | |
fmt.Printf("%v\n", sysinfo) | |
} |
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 ( | |
"github.com/stathat/go" | |
"syscall" | |
"time" | |
) | |
const ( | |
MAIL = "XXXX" | |
Megabyte = 1024 * 1024 | |
) | |
type ezMap map[string]uint64 | |
func monitor() { | |
ezs := make(ezMap) | |
var sysinfo syscall.Sysinfo_t | |
syscall.Sysinfo(&sysinfo) | |
ezs["SharedMem"] = sysinfo.Sharedram / Megabyte | |
ezs["FreeMem"] = sysinfo.Freeram / Megabyte | |
ezs["BufferMem"] = sysinfo.Bufferram / Megabyte | |
ezs["FreeSwap"] = sysinfo.Freeswap / Megabyte | |
for key, value := range ezs { | |
stathat.PostEZValue(key, MAIL, float64(value)) | |
} | |
} | |
func main() { | |
t := time.Tick(time.Minute) | |
for { | |
select { | |
case <-t: | |
go monitor() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment