xesite/vendor/github.com/Xe/gopreload/sample/runtimeStatLogs/main.go

37 lines
577 B
Go
Raw Normal View History

2017-12-13 18:43:58 +00:00
package main
import (
"runtime"
"time"
"github.com/Xe/ln"
)
func init() {
ln.Log(ln.F{
"action": "started_up",
"every": "20_seconds",
"what": "gc_metrics",
})
go func() {
for {
time.Sleep(20 * time.Second)
gatherMetrics()
}
}()
}
func gatherMetrics() {
stats := &runtime.MemStats{}
runtime.ReadMemStats(stats)
ln.Log(ln.F{
"gc-collections": stats.NumGC,
"gc-stw-pause-total": stats.PauseTotalNs,
"live-object-count": stats.Mallocs - stats.Frees,
"heap-bytes": stats.Alloc,
"stack-bytes": stats.StackInuse,
})
}