概述目标:统一收集应用的日志/指标/追踪并路由到后端系统,实现端到端可观测。适用:多语言服务、集中采集、跨环境观测。核心与实战Collector配置(使用contrib Loki exporter):receivers:

otlp:

protocols:

grpc:

http:

exporters:

prometheus:

endpoint: 0.0.0.0:9464

loki:

endpoint: http://loki:3100/loki/api/v1/push

default_labels_enabled:

exporter: true

resource: true

otlphttp/tempo:

endpoint: http://tempo:4318

processors:

batch:

attributes/log_labels:

actions:

- key: service.name

action: upsert

service:

pipelines:

logs:

receivers: [otlp]

processors: [attributes/log_labels, batch]

exporters: [loki]

metrics:

receivers: [otlp]

processors: [batch]

exporters: [prometheus]

traces:

receivers: [otlp]

processors: [batch]

exporters: [otlphttp/tempo]

示例运行与端点:otelcol-contrib --config collector.yaml

curl -s http://localhost:9464/metrics | head

应用侧OTLP导出:OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4317

OTEL_RESOURCE_ATTRIBUTES=service.name=api,service.namespace=prod

验证与监控后端命中:Loki中查看日志标签;Prometheus中观察指标;Tempo中查询trace。Collector健康:观察Collector自暴露指标(otelcol_*)与处理队列;查看错误日志。路由正确性:确保各pipeline只向指定后端导出,避免混乱。常见误区未使用contrib版本导致缺少Loki exporter;需使用`otelcol-contrib`。资源标签缺失导致后端难以查询;应在`attributes`处理器补充关键标签。混用Prometheus exporter与remote_write;本示例为本地暴露,由Prometheus抓取。结语通过Collector统一管道,将日志/指标/追踪分别导出至对应后端,实现一致的可观测体系与易于维护的配置。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部