Skip to content

Instantly share code, notes, and snippets.

@Marthym
Created July 22, 2023 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marthym/08cc94813c4e80c270fa9b7122a75b8c to your computer and use it in GitHub Desktop.
Save Marthym/08cc94813c4e80c270fa9b7122a75b8c to your computer and use it in GitHub Desktop.
Grafana Stack 📈 3. Collecte des logs avec OpenTelemetry
---
version: "3.9"
services:
myapp:
image: marthym/myapp:latest
restart: unless-stopped
read_only: true
environment:
- SPRING_MAIN_BANNER-MODE
- SPRING_PROFILES_ACTIVE
labels:
application: myapp
logging:
driver: json-file
options:
labels: 'application'
tag: 'id={{.ID}} name={{.Name}} image={{.ImageName}}'
max-size: 12m
max-file: '5'
networks:
myappnet: {}
prometheus:
image: prom/prometheus:v2.44.0
restart: unless-stopped
command:
- --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.path=/prometheus
- --web.console.libraries=/usr/share/prometheus/console_libraries
- --web.console.templates=/usr/share/prometheus/consoles
volumes:
- /opt/bw/prometheus/:/etc/prometheus/
- prometheus_data:/prometheus
networks:
metrics: {}
services:
loki:
image: grafana/loki:2.8.1
restart: unless-stopped
command:
- -config.file=/etc/loki/local-config.yaml
- -config.expand-env=true
volumes:
- ./.compose/loki/local-config.yaml:/etc/loki/local-config.yaml
- loki_data:/loki
networks:
metrics:
opentelemetry:
image: otel/opentelemetry-collector-contrib:0.77.0
user: 0:0
command:
- --config=/etc/otel/receivers.yaml
- --config=/etc/otel/processors.yaml
- --config=/etc/otel/exporters.yaml
- --config=/etc/otel/service.yaml
logging:
driver: local
options:
max-size: 10m
volumes:
- /opt/opentelemetry:/etc/otel:ro
networks:
myappnet: {}
metrics: {}
volumes:
prometheus_data: {}
loki_data: {}
networks:
metrics: {}
myappnet: {}
auth_enabled: false
server:
http_listen_port: ${LOKI_LISTEN_PORT:-3100}
common:
path_prefix: /loki
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
compactor:
retention_enabled: true
limits_config:
retention_period: ${LOKI_RETENTION_PERIOD:-30d}
schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h
ruler:
alertmanager_url: http://localhost:9093
exporters:
prometheus:
endpoint: '0.0.0.0:9091'
send_timestamps: true
enable_open_metrics: true
loki:
endpoint: 'http://loki:3100/loki/api/v1/push'
logging:
verbosity: detailed
receivers:
prometheus/myapp:
config:
scrape_configs:
- job_name: 'otel-collector'
scrape_interval: 15s
metrics_path: '/actuator/prometheus'
# Si vous avez sécurisé la route comme précognisé dans l’article précédent
# basic_auth:
# username: "otel_collector"
# password: "otel_password"
static_configs:
- targets: [myappservice:8081]
labels:
platform: 'prod'
filelog/containers:
include: ["/var/lib/docker/containers/*/*.log"]
start_at: end
include_file_path: false
include_file_name: false
operators:
- type: json_parser
timestamp:
parse_from: attributes.time
layout: '%Y-%m-%dT%H:%M:%S.%LZ'
- type: filter
expr: '(attributes?.attrs?.tag ?? "empty") == "empty"'
- type: key_value_parser
parse_from: attributes["attrs"]["tag"]
parse_to: resource.container
on_error: drop
- type: move
from: resource.container.id
to: resource.container_id
- type: move
from: resource.container.name
to: resource.container_name
- type: move
from: resource.container.image
to: resource.container_image
- type: move
from: attributes.log
to: body
- type: move
from: attributes["attrs"]["application"]
to: resource.application
- type: json_parser
timestamp:
parse_from: attributes.timestamp
layout: '%Y-%m-%dT%H:%M:%S.%LZ'
severity:
parse_from: attributes.level
mapping:
warn: WARN
error: ERROR
info: INFO
debug: DEBUG
- type: move
from: attributes.message
to: body
- type: remove
field: attributes.time
- type: remove
field: attributes.stream
- type: remove
field: attributes["timestamp"]
- type: remove
field: attributes["level"]
- type: remove
field: attributes["attrs"]
service:
pipelines:
metrics:
receivers: [prometheus/myapp]
processors: [batch]
exporters: [prometheus]
logs:
receivers: [filelog/containers]
processors: [attributes, batch]
exporters: [logging, loki]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment