prometheusreceiver

package
v0.0.0-...-300dff4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

README

Prometheus Receiver

Status
Stability beta
Supported pipeline types metrics
Distributions core, contrib

Receives metric data in Prometheus format. See the Design for additional information on this receiver.

⚠️ Warning

Note: This component is currently work in progress. It has several limitations and please don't use it if the following limitations is a concern:

  • Collector cannot auto-scale the scraping yet when multiple replicas of the collector is run.
  • When running multiple replicas of the collector with the same config, it will scrape the targets multiple times.
  • Users need to configure each replica with different scraping configuration if they want to manually shard the scraping.
  • The Prometheus receiver is a stateful component.

Unsupported features

The Prometheus receiver is meant to minimally be a drop-in replacement for Prometheus. However, there are advanced features of Prometheus that we don't support and thus explicitly will return an error for if the receiver's configuration YAML/code contains any of the following

  • alert_config.alertmanagers
  • alert_config.relabel_configs
  • remote_read
  • remote_write
  • rule_files

Getting Started

This receiver is a drop-in replacement for getting Prometheus to scrape your services. It supports the full set of Prometheus configuration in scrape_config, including service discovery. Just like you would write in a YAML configuration file before starting Prometheus, such as with:

Note: Since the collector configuration supports env variable substitution $ characters in your prometheus configuration are interpreted as environment variables. If you want to use $ characters in your prometheus configuration, you must escape them using $$.

prometheus --config.file=prom.yaml

Feature gates:

  • receiver.prometheusreceiver.UseCreatedMetric: Start time for Summary, Histogram and Sum metrics can be retrieved from _created metrics. Currently, this behaviour is disabled by default. To enable it, use the following feature gate option:
"--feature-gates=receiver.prometheusreceiver.UseCreatedMetric"

You can copy and paste that same configuration under:

receivers:
  prometheus:
    config:

For example:

receivers:
    prometheus:
      config:
        scrape_configs:
          - job_name: 'otel-collector'
            scrape_interval: 5s
            static_configs:
              - targets: ['0.0.0.0:8888']
          - job_name: k8s
            kubernetes_sd_configs:
            - role: pod
            relabel_configs:
            - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
              regex: "true"
              action: keep
            metric_relabel_configs:
            - source_labels: [__name__]
              regex: "(request_duration_seconds.*|response_duration_seconds.*)"
              action: keep

OpenTelemetry Operator

Additional to this static job definitions this receiver allows to query a list of jobs from the OpenTelemetryOperators TargetAllocator or a compatible endpoint.

receivers:
  prometheus:
    target_allocator:
      endpoint: http://my-targetallocator-service
      interval: 30s
      collector_id: collector-1

Exemplars

This receiver accepts exemplars coming in Prometheus format and converts it to OTLP format.

  1. Value is expected to be received in float64 format
  2. Timestamp is expected to be received in ms
  3. Labels with key span_id in prometheus exemplars are set as OTLP span id and labels with key trace_id are set as trace id
  4. Rest of the labels are copied as it is to OTLP format

Documentation

Overview

Package prometheusreceiver autodiscovers and scrapes Prometheus metrics handlers, often served at /metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFactory

func NewFactory() receiver.Factory

NewFactory creates a new Prometheus receiver factory.

Types

type Config

type Config struct {
	PrometheusConfig   *promconfig.Config `mapstructure:"-"`
	TrimMetricSuffixes bool               `mapstructure:"trim_metric_suffixes"`
	BufferPeriod       time.Duration      `mapstructure:"buffer_period"`
	BufferCount        int                `mapstructure:"buffer_count"`

	TargetAllocator *targetAllocator `mapstructure:"target_allocator"`

	// ConfigPlaceholder is just an entry to make the configuration pass a check
	// that requires that all keys present in the config actually exist on the
	// structure, ie.: it will error if an unknown key is present.
	ConfigPlaceholder interface{} `mapstructure:"config"`

	// Settings for adjusting metrics. Will default to using an InitialPointAdjuster
	// which will use the first scraped point to define the start time for the timeseries.
	AdjusterOpts MetricAdjusterOpts `mapstructure:",squash"`
}

Config defines configuration for Prometheus receiver.

func (*Config) Unmarshal

func (cfg *Config) Unmarshal(componentParser *confmap.Conf) error

Unmarshal a config.Parser into the config struct.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate checks the receiver configuration is valid.

type MetricAdjusterOpts

type MetricAdjusterOpts struct {
	// UseStartTimeMetric enables retrieving the start time of all counter
	// metrics from the process_start_time_seconds metric. This is only correct
	// if all counters on that endpoint started after the process start time,
	// and the process is the only actor exporting the metric after the process
	// started. It should not be used in "exporters" which export counters that
	// may have started before the process itself. Use only if you know what you
	// are doing, as this may result in incorrect rate calculations.
	UseStartTimeMetric   bool   `mapstructure:"use_start_time_metric"`
	StartTimeMetricRegex string `mapstructure:"start_time_metric_regex"`

	// UseCollectorStartTimeFallback enables using a fallback start time if a
	// start time is otherwise unavailable when adjusting metrics. This would
	// happen if the UseStartTimeMetric is used but the application doesn't emit
	// a process_start_time_seconds metric or a metric that matches the
	// StartTimeMetricRegex provided.
	//
	// If enabled, the fallback start time used for adjusted metrics is an
	// approximation of the collector start time.
	//
	// This option should only be used when we can guarantee that the scraped
	// processes that emit metrics that started after the collector has started.
	UseCollectorStartTimeFallback bool `mapstructure:"use_collector_start_time_fallback"`
	// AllowCumulativeResets enables preserving resets of cumulative points when
	// the metric adjuster is used. Should be enabled if we expect cumulative
	// point resets AND we want to use the StartTimeMetricAdjuster. Note that
	// this will require that we cache the previous point for every timeseries,
	// and so can increase memory used by the collector.
	AllowCumulativeResets bool `mapstructure:"allow_cumulative_resets"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL