You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Prometheus无法读取OTEL数据问题排查及生产优化咨询

问题修复方案

1. 修正Prometheus Exporter监听地址

Collector的Prometheus Exporter配置中,endpoint需设置为0.0.0.0:6666,而非容器名collector:6666。该配置指定Exporter在容器内监听的端口,必须绑定到所有网卡才能被Prometheus抓取。

修改后的otel-collector-config.yml exporters部分:

exporters:
  prometheus:
    endpoint: "0.0.0.0:6666"
  jaeger:
    endpoint: "jaeger:14250"
    tls:
      insecure: true

2. 修正Java Agent的OTLP Endpoint

如果Java Agent与Collector在同一Docker网络中,需将otel.exporter.otlp.endpoint设置为http://collector:5555;若Agent运行在宿主机,需替换为宿主机IP或host.docker.internal:5555(Windows/macOS)。

修改后的tracer.properties:

otel.exporter.otlp.endpoint=http://collector:5555

3. 验证配置有效性

  • 查看Collector日志:docker logs collector,确认无prometheus exporter相关报错
  • 在Prometheus容器内执行curl collector:6666/metrics,检查是否有指标输出
  • 重启Collector容器:docker-compose restart collector

生产环境优化建议

1. 调整Batch处理器参数

原配置的send_batch_size:1和timeout:1s会导致高频请求,增加系统负载。生产环境建议调整为:

processors:
  batch:
    timeout: 10s
    send_batch_size: 8192
    send_batch_max_size: 8192

2. 固定镜像版本

避免使用latest标签,指定稳定版本号,防止镜像更新引发兼容性问题:

# 示例版本,可根据实际需求选择
image: otel/opentelemetry-collector-contrib:0.92.0
image: jaegertracing/all-in-one:1.49
image: prom/prometheus:2.47.0

3. 添加资源限制

为每个容器配置CPU、内存限制,避免资源耗尽:

# 在每个service下添加
resources:
  limits:
    memory: 512M
    cpus: "0.5"
  reservations:
    memory: 256M
    cpus: "0.25"

4. 启用健康检查

添加健康检查确保服务可用性:

# Collector健康检查示例
healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost:13133/healthz"]
  interval: 30s
  timeout: 10s
  retries: 3

# Prometheus健康检查示例
healthcheck:
  test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:9090/-/healthy"]
  interval: 30s
  timeout: 10s
  retries: 3

5. 数据持久化

为Prometheus配置持久化存储,避免容器重启丢失数据:

# Prometheus service下的volumes修改
volumes:
  - "./prometheus.yml:/etc/prometheus/prometheus.yml"
  - prometheus_data:/prometheus

# 在docker-compose.yml末尾添加
volumes:
  prometheus_data:

Jaeger生产环境建议改用Cassandra/Elasticsearch作为存储,替换默认的内存存储。

6. 启用TLS加密

对OTLP通信、Prometheus抓取启用TLS加密,防止明文传输敏感数据:

  • 为Collector的OTLP Receiver配置TLS证书
  • 配置Prometheus使用TLS抓取Collector指标

7. 集中日志收集

将容器日志接入Loki/ELK等集中日志系统,便于问题排查与监控。


内容的提问来源于stack exchange,提问作者ahrooran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 11:40:23