
otel/opentelemetry-collectorOpenTelemetry Collector (Core) 镜像是 OpenTelemetry 官方提供的核心发行版容器镜像,基于 open-telemetry/opentelemetry-collector 仓库构建,包含 Collector 的核心组件。其主要用途是作为遥测数据(traces、metrics、logs)的统一处理管道,实现对分布式系统中遥测数据的收集、处理、聚合与导出,简化可观测性数据的管理流程。
包含遥测数据处理的核心组件:
支持三大遥测信号的统一处理:
通过 YAML 配置文件定义数据处理管道,支持自定义接收器、处理器、导出器的组合,满足不同场景的遥测需求。
在微服务集群中部署,统一收集各服务产生的遥测数据,避免多服务各自对接监控系统的复杂性。
作为跨环境的遥测数据网关,整合来自私有云、公有云、边缘环境的遥测数据,实现统一监控视图。
在边缘节点或本地数据中心部署,聚合分散的遥测数据后批量导出,减少对后端系统的请求压力。
通过接收器/导出器适配非 OpenTelemetry 协议的系统(如 Zipkin、Fluentd 等),实现现有监控工具的平滑迁移。
docker run 命令通过挂载本地配置文件启动 Collector:
bashdocker run -d \ --name otel-collector \ -p 4317:4317 # OTLP gRPC 端口(根据配置的接收器调整) \ -v $(pwd)/otel-config.yaml:/etc/otelcol/config.yaml \ # 挂载本地配置文件 otel/opentelemetry-collector:latest # 镜像名称(推荐指定具体版本,如 v0.91.0)
说明:
-p 4317:4317为 OTLP gRPC 接收器默认端口,需根据配置文件中的接收器调整端口映射(如 HTTP 接收器端口 4318)。
创建 docker-compose.yml:
yamlversion: '3.8' services: otel-collector: image: otel/opentelemetry-collector:latest container_name: otel-collector ports: - "4317:4317" # OTLP gRPC - "4318:4318" # OTLP HTTP volumes: - ./otel-config.yaml:/etc/otelcol/config.yaml # 挂载配置文件 environment: - OTEL_LOG_LEVEL=info # 日志级别(可选,默认 info) restart: unless-stopped
启动服务:
bashdocker-compose up -d
Collector 通过 YAML 配置文件定义数据处理流程,核心结构如下:
yaml# 接收器配置 receivers: # 示例:启用 OTLP 接收器(gRPC + HTTP) otlp: protocols: grpc: endpoint: 0.0.0.0:4317 # 容器内监听地址(需映射宿主机端口) http: endpoint: 0.0.0.0:4318 # 处理器配置 processors: # 示例:启用批处理(减少导出请求次数) batch: send_batch_size: 1024 timeout: 5s # 导出器配置 exporters: # 示例:导出至 Jaeger(Traces) jaeger: endpoint: "jaeger:***" tls: insecure: true # 示例:导出至 Prometheus(Metrics) prometheus: endpoint: "0.0.0.0:8889" resource_to_telemetry_conversion: enabled: true # 服务配置:定义数据处理管道 service: pipelines: traces: receivers: [otlp] # 使用 OTLP 接收器 processors: [batch] # 使用批处理处理器 exporters: [jaeger] # 导出至 Jaeger metrics: receivers: [otlp] processors: [batch] exporters: [prometheus]
Collector 启动时需加载配置文件,默认读取容器内路径 /etc/otelcol/config.yaml。通过 Docker volumes 将本地配置文件挂载至该路径即可生效:
bash-v /本地路径/otel-config.yaml:/etc/otelcol/config.yaml
Collector 的行为主要通过 配置文件 定义,核心配置参数如下:
receivers 部分定义数据接收方式,每个接收器需指定协议和监听地址。常见接收器配置示例:
yamlreceivers: otlp: protocols: grpc: endpoint: "0.0.0.0:4317" # gRPC 端口 http: endpoint: "0.0.0.0:4318" # HTTP 端口
yamlreceivers: prometheus: config: scrape_configs: - job_name: "otel-collector" static_configs: - targets: ["localhost:8888"]
processors 部分定义数据处理逻辑,常见处理器:
batch:批处理数据,减少导出请求次数。
yamlprocessors: batch: send_batch_size: 1024 # 批处理大小 timeout: 5s # 超时时间(达到超时后即使未达 batch 大小也导出)
memory_limiter:限制内存使用,避免 OOM。
yamlprocessors: memory_limiter: check_interval: 5s limit_mib: 512 # 内存限制(MiB) spike_limit_mib: 128 # 突发内存限制(MiB)
exporters 部分定义数据导出目标,常见导出器:
yamlexporters: otlp/backend: endpoint: "backend-collector:4317" tls: insecure: true
yamlexporters: jaeger: endpoint: "jaeger:***" # Jaeger gRPC 接收端口 tls: insecure: true
service.pipelines 部分定义数据处理管道,关联接收器、处理器、导出器:
yamlservice: pipelines: traces: # traces 管道 receivers: [otlp] # 从 otlp 接收器接收 processors: [memory_limiter, batch] # 依次通过 memory_limiter 和 batch 处理器 exporters: [jaeger] # 导出至 jaeger 导出器 metrics: # metrics 管道 receivers: [otlp, prometheus] processors: [batch] exporters: [prometheus]
Collector 支持通过环境变量调整运行时行为,常见变量如下:
| 环境变量名 | 说明 | 默认值 |
|---|---|---|
OTEL_CONFIG_FILE | 配置文件路径(容器内路径) | /etc/otelcol/config.yaml |
OTEL_LOG_LEVEL | 日志级别(debug, info, warn, error) | info |
OTEL_RESOURCE_ATTRIBUTES | 全局资源属性(如服务名、环境等) | 无(需手动指定,格式:key=value,key2=value2) |
otelcol-contrib --config=otel-config.yaml --validate 校验配置文件语法(需本地安装 Collector 二进制)。v0.91.0),避免 latest 标签带来的版本不确定性。
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务