Add Go memstats to statistics

pull/3999/head
Philip O'Toole 2015-09-04 13:14:38 -07:00
parent 13dbc8f0ba
commit f96ec228a4
4 changed files with 32 additions and 37 deletions

View File

@ -4,33 +4,9 @@ import (
"runtime"
)
// goRuntime captures Go runtime statistics and implements the monitor client interface
// goRuntime captures Go runtime diagnostics
type goRuntime struct{}
// Statistics returns the statistics for the goRuntime type
func (g *goRuntime) Statistics() (map[string]interface{}, error) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
return map[string]interface{}{
"Alloc": int64(m.Alloc),
"TotalAlloc": int64(m.TotalAlloc),
"Sys": int64(m.Sys),
"Lookups": int64(m.Lookups),
"Mallocs": int64(m.Mallocs),
"Frees": int64(m.Frees),
"HeapAlloc": int64(m.HeapAlloc),
"HeapSys": int64(m.HeapSys),
"HeapIdle": int64(m.HeapIdle),
"HeapInUse": int64(m.HeapInuse),
"HeapReleased": int64(m.HeapReleased),
"HeapObjects": int64(m.HeapObjects),
"PauseTotalNs": int64(m.PauseTotalNs),
"NumGC": int64(m.NumGC),
"NumGoroutine": int64(runtime.NumGoroutine()),
}, nil
}
func (g *goRuntime) Diagnostics() (*Diagnostic, error) {
diagnostics := map[string]interface{}{
"GOARCH": runtime.GOARCH,

View File

@ -4,14 +4,9 @@ import (
"os"
)
// network captures network statistics and implements the monitor client interface
// network captures network diagnostics
type network struct{}
// Statistics returns the statistics for the network type
func (n *network) Statistics() (map[string]interface{}, error) {
return nil, nil
}
func (n *network) Diagnostics() (*Diagnostic, error) {
h, err := os.Hostname()
if err != nil {

View File

@ -4,6 +4,7 @@ import (
"expvar"
"log"
"os"
"runtime"
"sort"
"strconv"
"sync"
@ -202,9 +203,37 @@ func (m *Monitor) Statistics() ([]*statistic, error) {
if len(statistic.Values) == 0 {
return
}
statistics = append(statistics, statistic)
})
// Add Go memstats.
statistic := &statistic{
Name: "runtime",
Tags: make(map[string]string),
Values: make(map[string]interface{}),
}
var rt runtime.MemStats
runtime.ReadMemStats(&rt)
statistic.Values = map[string]interface{}{
"Alloc": int64(rt.Alloc),
"TotalAlloc": int64(rt.TotalAlloc),
"Sys": int64(rt.Sys),
"Lookups": int64(rt.Lookups),
"Mallocs": int64(rt.Mallocs),
"Frees": int64(rt.Frees),
"HeapAlloc": int64(rt.HeapAlloc),
"HeapSys": int64(rt.HeapSys),
"HeapIdle": int64(rt.HeapIdle),
"HeapInUse": int64(rt.HeapInuse),
"HeapReleased": int64(rt.HeapReleased),
"HeapObjects": int64(rt.HeapObjects),
"PauseTotalNs": int64(rt.PauseTotalNs),
"NumGC": int64(rt.NumGC),
"NumGoroutine": int64(runtime.NumGoroutine()),
}
statistics = append(statistics, statistic)
return statistics, nil
}

View File

@ -11,14 +11,9 @@ func init() {
startTime = time.Now().UTC()
}
// system captures network statistics and implements the monitor client interface
// system captures system-level diagnostics
type system struct{}
// Statistics returns the statistics for the system type
func (s *system) Statistics() (map[string]interface{}, error) {
return nil, nil
}
func (s *system) Diagnostics() (*Diagnostic, error) {
diagnostics := map[string]interface{}{
"PID": os.Getpid(),