Skip to main content

OpenTelemetry Collector

Overview​

OTel Collector digunakan untuk telemetry collection (metrics, logs, traces).

Configuration​

Docker Compose​

otel-collector:
image: otel/opentelemetry-collector-contrib:0.155.0
container_name: otel-collector
command: ["--config=/etc/otelcol/config.yaml"]
environment:
- KUBECONFIG=/root/.kube/config
- KUBERNETES_MASTER=https://10.8.0.48:6443
volumes:
- ./configs/otel-collector/config.yaml:/etc/otelcol/config.yaml:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- /var/lib/docker/containers:/var/lib/docker/containers:ro
- ${KUBE_CONFIG:-/tmp/k3s.yaml/config}:/root/.kube/config:ro
ports:
- "4317:4317" # OTLP gRPC
- "4318:4318" # OTLP HTTP
- "8888:8888" # zPages
- "8889:8889" # Prometheus scrape
mem_limit: 512m
cpus: "0.50"

config.yaml​

receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318

prometheus:
config:
scrape_configs:
- job_name: 'otel-collector'
scrape_interval: 30s
static_configs:
- targets: ['localhost:8889']

docker_stats:
endpoint: unix:///var/run/docker.sock
collection_interval: 30s

hostmetrics:
collection_interval: 30s
scrapers:
cpu:
memory:
disk:
network:

processors:
batch:
timeout: 5s
send_batch_size: 1000

memory_limiter:
check_interval: 5s
limit_mib: 400
spike_limit_mib: 100

exporters:
opensearch:
endpoints: ["https://opensearch:9200"]
username: admin
password: MyStrong@OpenSearch2026!
tls:
insecure: true
logs_index: otel-logs-%{yyyy.MM.dd}
metrics_index: otel-metrics-%{yyyy.MM.dd}
traces_index: otel-traces-%{yyyy.MM.dd}

prometheus:
endpoint: "0.0.0.0:8889"

service:
pipelines:
metrics:
receivers: [otlp, prometheus, hostmetrics]
processors: [memory_limiter, batch]
exporters: [opensearch, prometheus]
logs:
receivers: [otlp, docker_stats]
processors: [memory_limiter, batch]
exporters: [opensearch]
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [opensearch]

Receivers​

OTLP Receiver​

ProtocolPortDescription
gRPC4317OTLP gRPC
HTTP4318OTLP HTTP

Prometheus Receiver​

Scrapes metrics from Prometheus endpoints.

Docker Stats Receiver​

Collects container metrics from Docker socket.

Hostmetrics Receiver​

Collects host metrics (CPU, memory, disk, network).

Processors​

Batch​

Batches telemetry data before export.

Memory Limiter​

Limits memory usage to prevent OOM.

Exporters​

OpenSearch Exporter​

Exports telemetry to OpenSearch.

Prometheus Exporter​

Exports metrics for Prometheus scraping.

Monitoring​

zPages​

http://localhost:8888

Health Check​

curl http://localhost:8889/metrics

Next Steps​