// Collect returns the current state of all metrics of the collector. func (c *goCollector) Collect(ch chan<- Metric) { c.goroutines.Set(float64(runtime.NumGoroutine())) ch <- c.goroutines var stats debug.GCStats stats.PauseQuantiles = make([]time.Duration, 5) debug.ReadGCStats(&stats) quantiles := make(map[float64]float64) for idx, pq := range stats.PauseQuantiles[1:] { quantiles[float64(idx+1)/float64(len(stats.PauseQuantiles)-1)] = pq.Seconds() } quantiles[0.0] = stats.PauseQuantiles[0].Seconds() ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles) }
func (rm *RuntimeMetrics) Report() { var mem runtime.MemStats runtime.ReadMemStats(&mem) if rm.options.Memory { // bytes allocated and not yet freed rm.reportGauge("alloc", float64(mem.Alloc)) // total number of allocated objects rm.reportGauge("heap_objects", float64(mem.HeapObjects)) } if rm.options.GC { rm.reportGauge("pause_total_ns", float64(mem.PauseTotalNs)) rm.reportGauge("num_gc", float64(mem.NumGC)) rm.reportGauge("next_gc", float64(mem.NextGC)) rm.reportGauge("gc_cpu_fraction", mem.GCCPUFraction) } if rm.options.GCQuantile { var gc debug.GCStats gc.PauseQuantiles = make([]time.Duration, 3) debug.ReadGCStats(&gc) rm.reportGauge("gc_pause_quantile_50", float64(gc.PauseQuantiles[1]/1000)/1000.0) rm.reportGauge("gc_pause_quantile_max", float64(gc.PauseQuantiles[2]/1000)/1000.0) } if rm.options.Goroutines { rm.reportGauge("num_goroutines", float64(runtime.NumGoroutine())) } if rm.options.Cgo { rm.reportGauge("num_cgo_call", float64(runtime.NumCgoCall())) } if rm.options.FDs { if num, err := getFDUsage(); err == nil { rm.reportGauge("num_fds_used", float64(num)) } } }