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

Method CollectMetrics

modules/generator/registry/registry.go:234–281  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

232}
233
234func (r *ManagedRegistry) CollectMetrics(ctx context.Context) {
235 r.metricsMtx.RLock()
236 defer r.metricsMtx.RUnlock()
237
238 var err error
239 var seriesDemand int
240
241 for _, m := range r.metrics {
242 seriesDemand += m.countSeriesDemand()
243 }
244
245 r.metricSeriesDemand.Set(float64(seriesDemand))
246 r.metricEntityDemand.Set(float64(r.entityDemand.Estimate()))
247
248 if r.overrides.MetricsGeneratorDisableCollection(r.tenant) {
249 return
250 }
251
252 defer func() {
253 r.metricTotalCollections.Inc()
254 if err != nil {
255 errT := getErrType(err)
256 level.Error(r.logger).Log("msg", "collecting metrics failed", "err", err)
257 metricFailedCollections.WithLabelValues(r.tenant, errT).Inc()
258 }
259 }()
260
261 appender := r.appendable.Appender(ctx)
262 collectionTimeMs := time.Now().UnixMilli()
263
264 for _, m := range r.metrics {
265 if err = m.collectMetrics(appender, collectionTimeMs); err != nil {
266 return
267 }
268 }
269
270 // Try to avoid committing after we have started the shutdown process.
271 if ctx.Err() != nil { // shutdown
272 return
273 }
274
275 // If the shutdown has started here, a "file already closed" error will be
276 // observed here.
277 err = appender.Commit()
278 if err != nil {
279 return
280 }
281}
282
283func (r *ManagedRegistry) collectionInterval() time.Duration {
284 interval := r.overrides.MetricsGeneratorCollectionInterval(r.tenant)

Calls 12

getErrTypeFunction · 0.85
EstimateMethod · 0.80
countSeriesDemandMethod · 0.65
SetMethod · 0.65
IncMethod · 0.65
LogMethod · 0.65
ErrorMethod · 0.65
NowMethod · 0.65
collectMetricsMethod · 0.65
AppenderMethod · 0.45
CommitMethod · 0.45