factory.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package collectdreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/collectdreceiver"
  4. import (
  5. "context"
  6. "time"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/config/confighttp"
  9. "go.opentelemetry.io/collector/consumer"
  10. "go.opentelemetry.io/collector/receiver"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/collectdreceiver/internal/metadata"
  12. )
  13. // This file implements factory for CollectD receiver.
  14. const (
  15. defaultBindEndpoint = "localhost:8081"
  16. defaultEncodingFormat = "json"
  17. )
  18. // NewFactory creates a factory for collectd receiver.
  19. func NewFactory() receiver.Factory {
  20. return receiver.NewFactory(
  21. metadata.Type,
  22. createDefaultConfig,
  23. receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
  24. }
  25. func createDefaultConfig() component.Config {
  26. return &Config{
  27. HTTPServerSettings: confighttp.HTTPServerSettings{
  28. Endpoint: defaultBindEndpoint,
  29. },
  30. Timeout: 30 * time.Second,
  31. Encoding: defaultEncodingFormat,
  32. }
  33. }
  34. func createMetricsReceiver(
  35. _ context.Context,
  36. cs receiver.CreateSettings,
  37. cfg component.Config,
  38. nextConsumer consumer.Metrics,
  39. ) (receiver.Metrics, error) {
  40. c := cfg.(*Config)
  41. return newCollectdReceiver(cs.Logger, c, c.AttributesPrefix, nextConsumer, cs)
  42. }