rcrowley / go-metrics

Go port of Coda Hale's Metrics library
Other
3.43k stars 493 forks source link

CaptureDebugGCStats panics #276

Open Setheck opened 4 years ago

Setheck commented 4 years ago

Just wanted to explore what GC stats were getting captured, so i added go metrics.CaptureDebugGCStats(metrics.DefaultRegistry, 10*time.Second)

and It appears to panic because debugMetrics.ReadGCStats is a Timer interface that is never initialized.

version from go.mod is github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0

hspens commented 3 years ago

I experienced the same issue and it appears that you need to register the stats prior to using the capture function.

Example:

package main

import (
    metrics "github.com/rcrowley/go-metrics"
)

func main() {
  metrics.RegisterDebugGCStats(metrics.DefaultRegistry)
  metrics.RegisterRuntimeMemStats(metrics.DefaultRegistry)

  go metrics.CaptureDebugGCStats(metrics.DefaultRegistry, 10*time.Second)
  go metrics.CaptureRuntimeMemStats(metrics.DefaultRegistry, 10*time.Second)

  go metrics.Log(metrics.DefaultRegistry, 2*time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds))

  for { select{ } }
}