-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
47 lines (40 loc) · 1.1 KB
/
factory.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
44
45
46
47
package disksusagemetricsreceiver
import (
"context"
"github.com/ridzuan5757/disksusagemetrics/internal/metadata"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scraperhelper"
)
func newMetricReceiver(
_ context.Context,
set receiver.CreateSettings,
rCfg component.Config,
consumer consumer.Metrics,
) (receiver.Metrics, error) {
cfg, _ := rCfg.(*Config)
metricsBuilder := metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, set)
ns := newScraper(metricsBuilder, set.Logger, cfg)
scraper, err := scraperhelper.NewScraper(
metadata.Type.String(),
ns.scrape,
)
if err != nil {
ns.logger.Error("Failed to create scraper helper.")
return nil, err
}
return scraperhelper.NewScraperControllerReceiver(
&cfg.ScraperControllerSettings,
set,
consumer,
scraperhelper.AddScraper(scraper),
)
}
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
receiver.WithMetrics(newMetricReceiver, metadata.MetricsStability),
)
}