|
| 1 | +// Copyright 2019, OpenTelemetry Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package vmmetricsreceiver |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + |
| 20 | + "go.uber.org/zap" |
| 21 | + |
| 22 | + "github.com/open-telemetry/opentelemetry-service/consumer" |
| 23 | + "github.com/open-telemetry/opentelemetry-service/models" |
| 24 | + "github.com/open-telemetry/opentelemetry-service/receiver" |
| 25 | +) |
| 26 | + |
| 27 | +// This file implements factory for VMMetrics receiver. |
| 28 | + |
| 29 | +var _ = receiver.RegisterReceiverFactory(&Factory{}) |
| 30 | + |
| 31 | +const ( |
| 32 | + // The value of "type" key in configuration. |
| 33 | + typeStr = "vmmetrics" |
| 34 | +) |
| 35 | + |
| 36 | +// Factory is the factory for receiver. |
| 37 | +type Factory struct { |
| 38 | +} |
| 39 | + |
| 40 | +// Type gets the type of the Receiver config created by this factory. |
| 41 | +func (f *Factory) Type() string { |
| 42 | + return typeStr |
| 43 | +} |
| 44 | + |
| 45 | +// CustomUnmarshaler returns custom unmarshaler for this config. |
| 46 | +func (f *Factory) CustomUnmarshaler() receiver.CustomUnmarshaler { |
| 47 | + return nil |
| 48 | +} |
| 49 | + |
| 50 | +// CreateDefaultConfig creates the default configuration for receiver. |
| 51 | +func (f *Factory) CreateDefaultConfig() models.Receiver { |
| 52 | + return &ConfigV2{ |
| 53 | + ReceiverSettings: models.ReceiverSettings{ |
| 54 | + TypeVal: typeStr, |
| 55 | + NameVal: typeStr, |
| 56 | + }, |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +// CreateTraceReceiver creates a trace receiver based on provided config. |
| 61 | +func (f *Factory) CreateTraceReceiver( |
| 62 | + ctx context.Context, |
| 63 | + logger *zap.Logger, |
| 64 | + cfg models.Receiver, |
| 65 | + nextConsumer consumer.TraceConsumer, |
| 66 | +) (receiver.TraceReceiver, error) { |
| 67 | + // Prometheus does not support traces |
| 68 | + return nil, models.ErrDataTypeIsNotSupported |
| 69 | +} |
| 70 | + |
| 71 | +// CreateMetricsReceiver creates a metrics receiver based on provided config. |
| 72 | +func (f *Factory) CreateMetricsReceiver( |
| 73 | + logger *zap.Logger, |
| 74 | + config models.Receiver, |
| 75 | + consumer consumer.MetricsConsumer, |
| 76 | +) (receiver.MetricsReceiver, error) { |
| 77 | + |
| 78 | + cfg := config.(*ConfigV2) |
| 79 | + |
| 80 | + vmc, err := NewVMMetricsCollector(cfg.ScrapeInterval, cfg.MountPoint, cfg.ProcessMountPoint, cfg.MetricPrefix, consumer) |
| 81 | + if err != nil { |
| 82 | + return nil, err |
| 83 | + } |
| 84 | + |
| 85 | + vmr := &Receiver{ |
| 86 | + vmc: vmc, |
| 87 | + } |
| 88 | + return vmr, nil |
| 89 | +} |
0 commit comments