diff options
| author | Chris Lu <chris.lu@gmail.com> | 2014-03-26 13:22:27 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2014-03-26 13:22:27 -0700 |
| commit | 59f6a13609e63d23ffd4410edce38223a5705232 (patch) | |
| tree | 1771a059d05e298f032d30537b5fdfe7bc9a77d3 /go/stats/memory.go | |
| parent | 39b774a131ac3bc454a516f7b72dcefabc593103 (diff) | |
| download | seaweedfs-59f6a13609e63d23ffd4410edce38223a5705232.tar.xz seaweedfs-59f6a13609e63d23ffd4410edce38223a5705232.zip | |
adding lots of different stats
Diffstat (limited to 'go/stats/memory.go')
| -rw-r--r-- | go/stats/memory.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/go/stats/memory.go b/go/stats/memory.go new file mode 100644 index 000000000..b899e1e4e --- /dev/null +++ b/go/stats/memory.go @@ -0,0 +1,38 @@ +// +build !windows + +package stats + +import ( + "runtime" + "syscall" +) + +type MemStatus struct { + Goroutines int + All uint64 + Used uint64 + Free uint64 + Self uint64 + Heap uint64 + Stack uint64 +} + +func MemStat() MemStatus { + mem := MemStatus{} + mem.Goroutines = runtime.NumGoroutine() + memStat := new(runtime.MemStats) + runtime.ReadMemStats(memStat) + mem.Self = memStat.Alloc + mem.Heap = memStat.HeapAlloc + mem.Stack = memStat.StackInuse + + //system memory usage + sysInfo := new(syscall.Sysinfo_t) + err := syscall.Sysinfo(sysInfo) + if err == nil { + mem.All = sysInfo.Totalram //* uint64(syscall.Getpagesize()) + mem.Free = sysInfo.Freeram //* uint64(syscall.Getpagesize()) + mem.Used = mem.All - mem.Free + } + return mem +} |
