MCPcopy
hub / github.com/crowdsecurity/crowdsec / GetMetrics

Function GetMetrics

pkg/acquisition/acquisition.go:415–443  ·  view source on GitHub ↗
(sources []types.DataSource, aggregated bool)

Source from the content-addressed store, hash-verified

413}
414
415func GetMetrics(sources []types.DataSource, aggregated bool) error {
416 for i := range sources {
417 mp, ok := sources[i].(types.MetricsProvider)
418 if !ok {
419 // the source does not expose metrics
420 continue
421 }
422
423 var metrics []prometheus.Collector
424
425 if aggregated {
426 metrics = mp.GetMetrics()
427 } else {
428 metrics = mp.GetAggregMetrics()
429 }
430
431 for _, metric := range metrics {
432 if err := prometheus.Register(metric); err != nil {
433 var alreadyRegisteredErr prometheus.AlreadyRegisteredError
434 if !errors.As(err, &alreadyRegisteredErr) {
435 return fmt.Errorf("could not register metrics for datasource %s: %w", sources[i].GetName(), err)
436 }
437 // ignore the error
438 }
439 }
440 }
441
442 return nil
443}
444
445// There's no need for an actual deep copy
446// The event is almost empty, we are mostly interested in allocating new maps for Parsed/Meta/...

Callers 1

startLPMetricsFunction · 0.92

Calls 3

GetMetricsMethod · 0.65
GetAggregMetricsMethod · 0.65
GetNameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…