3
0

add(sam):, pprof, goroutine num in expvar

This commit is contained in:
Tit Petric
2018-08-03 20:48:08 +02:00
parent dd2f377a48
commit 8256270ed7
2 changed files with 9 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"expvar"
"fmt"
"runtime"
"time"
@@ -21,8 +22,11 @@ type Monitor struct {
}
func NewMonitor(duration int) {
var m Monitor
var rtm runtime.MemStats
var (
m = Monitor{}
rtm runtime.MemStats
goroutines = expvar.NewInt("num_goroutine")
)
var interval = time.Duration(duration) * time.Second
for {
<-time.After(interval)
@@ -32,6 +36,7 @@ func NewMonitor(duration int) {
// Number of goroutines
m.NumGoroutine = runtime.NumGoroutine()
goroutines.Set(int64(m.NumGoroutine))
// Misc memory stats
m.Alloc = rtm.Alloc

View File

@@ -26,6 +26,8 @@ func MountRoutes(r chi.Router, opts *RouteOptions, mountRoutes ...func(r chi.Rou
r.Use(middleware.Logger)
}
r.Mount("/debug", middleware.Profiler())
for _, mount := range mountRoutes {
mount(r)
}