adding lots of different stats
This commit is contained in:
@@ -7,13 +7,14 @@ import (
|
||||
)
|
||||
|
||||
type DiskStatus struct {
|
||||
All uint64 `json:"all"`
|
||||
Used uint64 `json:"used"`
|
||||
Free uint64 `json:"free"`
|
||||
Dir string
|
||||
All uint64
|
||||
Used uint64
|
||||
Free uint64
|
||||
}
|
||||
|
||||
func DiskUsage(path string) (disk *DiskStatus) {
|
||||
disk = &DiskStatus{}
|
||||
func NewDiskStatus(path string) (disk *DiskStatus) {
|
||||
disk = &DiskStatus{Dir: path}
|
||||
fs := syscall.Statfs_t{}
|
||||
err := syscall.Statfs(path, &fs)
|
||||
if err != nil {
|
||||
|
||||
@@ -7,11 +7,12 @@ import (
|
||||
)
|
||||
|
||||
type DiskStatus struct {
|
||||
All uint64 `json:"all"`
|
||||
Used uint64 `json:"used"`
|
||||
Free uint64 `json:"free"`
|
||||
Dir string
|
||||
All uint64
|
||||
Used uint64
|
||||
Free uint64
|
||||
}
|
||||
|
||||
func DiskUsage(path string) (disk *DiskStatus) {
|
||||
func NewDiskStatus(path string) (disk *DiskStatus) {
|
||||
return
|
||||
}
|
||||
|
||||
38
go/stats/memory.go
Normal file
38
go/stats/memory.go
Normal file
@@ -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
|
||||
}
|
||||
29
go/stats/memory_windows.go
Normal file
29
go/stats/memory_windows.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// +build windows
|
||||
|
||||
package stats
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
)
|
||||
|
||||
type MemStatus struct {
|
||||
Goroutines uint32
|
||||
All uint32
|
||||
Used uint32
|
||||
Free uint32
|
||||
Self uint64
|
||||
Heap uint64
|
||||
Stack uint64
|
||||
}
|
||||
|
||||
func MemStat() MemStatus {
|
||||
memStat := new(runtime.MemStats)
|
||||
mem.Goroutines = runtime.NumGoroutine()
|
||||
runtime.ReadMemStats(memStat)
|
||||
mem := MemStatus{}
|
||||
mem.Self = memStat.Alloc
|
||||
mem.Heap = memStat.HeapAlloc
|
||||
mem.Stack = memStat.StackInuse
|
||||
|
||||
return mem
|
||||
}
|
||||
Reference in New Issue
Block a user