I'm trying to send metrics from my .NET 7 application to Prometheus. Since I am working with a .NET service instead of a ASP.NET Core app, the way to do this is by using the OTLP exporter and using the OpenTelemetry Collector, As stated by OpenTelemetry Here is the config.yaml
for opentelemetry collector
# /tmp/otel-collector-config.yaml
receivers:
otlp:
protocols:
http:
grpc:
exporters:
logging:
loglevel: debug
prometheus:
namespace: "otel"
endpoint: "localhost:6666" # what port?
processors:
batch:
service:
pipelines:
traces:
receivers: [otlp]
exporters: [logging]
processors: [batch]
metrics:
receivers: [otlp]
exporters: [logging, prometheus]
processors: [batch]
Here is my prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: 'opentelemetry-collector'
scrape_interval: 5s
static_configs:
- targets: ['docker.for.mac.localhost:6666'] # what port?
The way I start my opentelemtry collector is by running docker run -p 4317:4317 -v $(pwd)/config.yaml:/etc/otel-collector-config.yaml otel/opentelemetry-collector:latest --config=/etc/otel-collector-config.yaml
.
The way I start prometheus is by running docker run -p 9090:9090 -v /Users/VMCR87/Code/prometheus_config/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
When I start up prometheus, I get an error for my opentelemetry target, stating that Get "http://docker.for.mac.localhost:6666/metrics": dial tcp 192.168.65.2:6666: connect: connection refused
. Here is a screenshot
I suspect this is an issue with the targets not running inside my container, I have read some suggestions Here but those have not worked.
How exactly should I be running the collector and prometheus together so that prometheus can read metrics being sent from my application?