scraper.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal"
  4. import (
  5. "context"
  6. "github.com/shirou/gopsutil/v3/common"
  7. "go.opentelemetry.io/collector/receiver"
  8. "go.opentelemetry.io/collector/receiver/scraperhelper"
  9. )
  10. // ScraperFactory can create a MetricScraper.
  11. type ScraperFactory interface {
  12. // CreateDefaultConfig creates the default configuration for the Scraper.
  13. CreateDefaultConfig() Config
  14. // CreateMetricsScraper creates a scraper based on this config.
  15. // If the config is not valid, error will be returned instead.
  16. CreateMetricsScraper(ctx context.Context, settings receiver.CreateSettings, cfg Config) (scraperhelper.Scraper, error)
  17. }
  18. // Config is the configuration of a scraper.
  19. type Config interface {
  20. SetRootPath(rootPath string)
  21. SetEnvMap(envMap common.EnvMap)
  22. }
  23. type ScraperConfig struct {
  24. RootPath string `mapstructure:"-"`
  25. EnvMap common.EnvMap `mapstructure:"-"`
  26. }
  27. func (p *ScraperConfig) SetRootPath(rootPath string) {
  28. p.RootPath = rootPath
  29. }
  30. func (p *ScraperConfig) SetEnvMap(envMap common.EnvMap) {
  31. p.EnvMap = envMap
  32. }