Ejemplo n.º 1
0
// Run periodically calls m.updateHandler.
func (m *MetricTags) Run() {
	// Collect Go's runtime stats the first time this is run.
	metrics.RegisterDebugGCStats(m.registry)
	metrics.RegisterRuntimeMemStats(m.registry)

	updateTime := m.nowHandler()
	gcTime, memTime := updateTime, updateTime
	for {
		now := m.nowHandler()
		// Get GC runtime stats
		if now.Sub(gcTime) > m.StatsGCCollection {
			metrics.CaptureDebugGCStatsOnce(m.registry)
			gcTime = now
		}
		// Get memory runtime stats
		if now.Sub(memTime) > m.StatsMemCollection {
			metrics.CaptureRuntimeMemStatsOnce(m.registry)
			memTime = now
		}
		select {
		case <-m.quitCh:
			// Update stats one last time
			m.updateHandler()
			m.quitCh <- struct{}{}
			return
		case <-time.After(m.flushInterval):
			m.updateHandler()
		}
	}
}
Ejemplo n.º 2
0
func newMemoryMetricaDataSource(pollInterval int) goMetricaDataSource {
	r := metrics.NewRegistry()

	metrics.RegisterRuntimeMemStats(r)
	metrics.CaptureRuntimeMemStatsOnce(r)
	go metrics.CaptureRuntimeMemStats(r, time.Duration(pollInterval)*time.Second)
	return goMetricaDataSource{r}
}