You can configure the OpenTelemetryCollector
custom resource (CR) to create a Prometheus serviceMonitor
CR or a PodMonitor
CR for a sidecar deployment. A serviceMonitor
can scrape Collector’s internal metrics endpoint and Prometheus exporter metrics endpoints.
Example of the OpenTelemetry Collector CR with the Prometheus exporter
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
spec:
mode: deployment
observability:
metrics:
enableMetrics: true (1)
config: |
exporters:
prometheus:
endpoint: 0.0.0.0:8889
resource_to_telemetry_conversion:
enabled: true # by default resource attributes are dropped
service:
telemetry:
metrics:
address: ":8888"
pipelines:
metrics:
receivers: [otlp]
exporters: [prometheus]
1 |
Configures the Red Hat build of OpenTelemetry Operator to create the Prometheus serviceMonitor CR or PodMonitor CR to scrape the Collector’s internal metrics endpoint and the Prometheus exporter metrics endpoints. |
|
Setting enableMetrics to true creates the following two serviceMonitor instances:
-
One serviceMonitor instance for the <instance_name>-collector-monitoring service. This serviceMonitor instance scrapes the Collector’s internal metrics.
-
One serviceMonitor instance for the <instance_name>-collector service. This serviceMonitor instance scrapes the metrics exposed by the Prometheus exporter instances.
|
Alternatively, a manually created Prometheus PodMonitor
CR can provide fine control, for example removing duplicated labels added during Prometheus scraping.
Example of the PodMonitor
CR that configures the monitoring stack to scrape the Collector metrics
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: otel-collector
spec:
selector:
matchLabels:
app.kubernetes.io/name: <cr_name>-collector (1)
podMetricsEndpoints:
- port: metrics (2)
- port: promexporter (3)
relabelings:
- action: labeldrop
regex: pod
- action: labeldrop
regex: container
- action: labeldrop
regex: endpoint
metricRelabelings:
- action: labeldrop
regex: instance
- action: labeldrop
regex: job
1 |
The name of the OpenTelemetry Collector CR. |
2 |
The name of the internal metrics port for the OpenTelemetry Collector. This port name is always metrics . |
3 |
The name of the Prometheus exporter port for the OpenTelemetry Collector. |