MCPcopy
hub / github.com/prometheus/client_golang / Collect

Method Collect

prometheus/go_collector.go:244–262  ·  view source on GitHub ↗

Collect returns the current state of all metrics of the collector.

(ch chan<- Metric)

Source from the content-addressed store, hash-verified

242
243// Collect returns the current state of all metrics of the collector.
244func (c *baseGoCollector) Collect(ch chan<- Metric) {
245 ch <- MustNewConstMetric(c.goroutinesDesc, GaugeValue, float64(runtime.NumGoroutine()))
246
247 n := getRuntimeNumThreads()
248 ch <- MustNewConstMetric(c.threadsDesc, GaugeValue, n)
249
250 var stats debug.GCStats
251 stats.PauseQuantiles = make([]time.Duration, 5)
252 debug.ReadGCStats(&stats)
253
254 quantiles := make(map[float64]float64)
255 for idx, pq := range stats.PauseQuantiles[1:] {
256 quantiles[float64(idx+1)/float64(len(stats.PauseQuantiles)-1)] = pq.Seconds()
257 }
258 quantiles[0.0] = stats.PauseQuantiles[0].Seconds()
259 ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), stats.PauseTotal.Seconds(), quantiles)
260 ch <- MustNewConstMetric(c.gcLastTimeDesc, GaugeValue, float64(stats.LastGC.UnixNano())/1e9)
261 ch <- MustNewConstMetric(c.goInfoDesc, GaugeValue, 1)
262}
263
264func memstatNamespace(s string) string {
265 return "go_memstats_" + s

Callers

nothing calls this directly

Calls 3

MustNewConstMetricFunction · 0.85
MustNewConstSummaryFunction · 0.85
getRuntimeNumThreadsFunction · 0.70

Tested by

no test coverage detected