I am using OpenTelemetry Collector to collect and export metrics from my application. I want to use the Prometheus exporter to expose my metrics on collector's endpoint which then can be scraped by prometheus, but I need to change the default path of the exporter from /metrics to /v1/metrics. How can I do that?
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
exporters:
prometheus:
endpoint: "0.0.0.0:10000"
service:
pipelines:
metrics:
receivers: [ otlp ]
exporters: [ prometheus ]
I have read the documentation of the Prometheus exporter, but I could not find any option to configure the path. I also searched on Google and Stack Overflow, but I did not find any relevant answers.
Is there a way to change the path of the Prometheus exporter in OpenTelemetry Collector? If so, how can I do it? Any help would be appreciated. Thank you.
What I have already tried:
when I try to try pass the path through the endpoint:
exporters:
prometheus:
endpoint: '0.0.0.0:10000/v1/metrics'
this is the error I receive:
Error: cannot start pipelines: listen tcp: address tcp/10000/v1/metrics: unknown port
2023/09/26 10:51:50 collector server run finished with error: cannot start pipelines: listen tcp: address tcp/10000/v1/metrics: unknown port
I want to use the Prometheus exporter to send metrics to a Prometheus backend
prometheus
exporter doesn't send metrics to Prometheus backend (this exporter only exposes metrics on the collector's endpoint, where path /metrics
is not configurable). You need prometheusremotewrite
exporter, which sends metrics to Prometheus backend, e.g.:
exporters:
prometheusremotewrite:
endpoint: "https://my-cortex:7900/api/v1/push"
Update:
As I said path /metrics
in prometheus
exporter is not configurable - it is hardcoded. See https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/5133f4ccd69fa40d016c5b7f2198fb6ac61007b4/exporter/prometheusexporter/prometheus.go#L69
So you can't expose your metrics on custom path, e.g. /v1/metrics
.
The only way is that you will create own fork of prometheus
exporter (and then build own collector), where you will implement own requirements.