Skip to content

Instantly share code, notes, and snippets.

@border
Created September 18, 2012 10:03
Show Gist options
  • Save border/3742368 to your computer and use it in GitHub Desktop.
Save border/3742368 to your computer and use it in GitHub Desktop.
monitormem.go
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)
}
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