MCPcopy
hub / github.com/grafana/tempo / buildMetrics

Function buildMetrics

pkg/usagestats/stats.go:113–145  ·  view source on GitHub ↗

buildMetrics builds the metrics part of the report to be sent to the stats server

()

Source from the content-addressed store, hash-verified

111
112// buildMetrics builds the metrics part of the report to be sent to the stats server
113func buildMetrics() map[string]interface{} {
114 result := map[string]interface{}{
115 "memstats": memstats(),
116 "num_cpu": runtime.NumCPU(),
117 "num_goroutine": runtime.NumGoroutine(),
118 }
119 expvar.Do(func(kv expvar.KeyValue) {
120 if !strings.HasPrefix(kv.Key, statsPrefix) || kv.Key == statsPrefix+targetKey || kv.Key == statsPrefix+editionKey {
121 return
122 }
123 var value interface{}
124 switch v := kv.Value.(type) {
125 case *expvar.Int:
126 value = v.Value()
127 case *expvar.Float:
128 value = v.Value()
129 case *expvar.String:
130 value = v.Value()
131 case *Statistics:
132 value = v.Value()
133 case *Counter:
134 v.updateRate()
135 value = v.Value()
136 v.reset()
137 case *WordCounter:
138 value = v.Value()
139 default:
140 value = v.String()
141 }
142 result[strings.TrimPrefix(kv.Key, statsPrefix)] = value
143 })
144 return result
145}
146
147func memstats() interface{} {
148 stats := new(runtime.MemStats)

Callers 1

BuildStatsFunction · 0.85

Calls 6

memstatsFunction · 0.85
updateRateMethod · 0.80
DoMethod · 0.65
ValueMethod · 0.45
resetMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected