forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
43 lines (33 loc) · 1011 Bytes
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package scraper // import "go.opentelemetry.io/collector/scraper"
import (
"context"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pmetric"
)
// Metrics is the base interface for metrics scrapers.
type Metrics interface {
component.Component
ScrapeMetrics(context.Context) (pmetric.Metrics, error)
}
// ScrapeMetricsFunc is a helper function that is similar to Metrics.ScrapeMetrics.
type ScrapeMetricsFunc ScrapeFunc[pmetric.Metrics]
func (sf ScrapeMetricsFunc) ScrapeMetrics(ctx context.Context) (pmetric.Metrics, error) {
return sf(ctx)
}
type metrics struct {
baseScraper
ScrapeMetricsFunc
}
// NewMetrics creates a new Metrics scraper.
func NewMetrics(scrape ScrapeMetricsFunc, options ...Option) (Metrics, error) {
if scrape == nil {
return nil, errNilFunc
}
bs := &metrics{
baseScraper: newBaseScraper(options),
ScrapeMetricsFunc: scrape,
}
return bs, nil
}