rcrowley / go-metrics

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

How do I stop logging metrics? #257

Open 4alexey opened 5 years ago

4alexey commented 5 years ago

Hi, I'd like to log metrics once after command execution, log them or print them out, and exit. However the call to metrics.Log(r, 10*time.Second, histoLog) blocks and continues logging the metrics. How do I print metrics once, clean up, and exit? Thanks!

histoLog := logrus.New()
histoLog.Out = os.Stdout
metrics.Log(r, 10*time.Second, histoLog)
4alexey commented 5 years ago

LogScaled uses time.Tick

func Tick(d Duration) <-chan Time

Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. While Tick is useful for clients that have no need to shut down the Ticker, be aware that without a way to shut it down the underlying Ticker cannot be recovered by the garbage collector; it "leaks". Unlike NewTicker, Tick will return nil if d <= 0.