# Promtail configuration — Smart City Digital Twin
# Collects Docker logs and sends to Loki

server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/promtail/positions.yaml

clients:
  - url: http://smart-city-loki:3100/loki/api/v1/push

scrape_configs:
  # Collect logs from all Docker containers
  - job_name: docker
    docker_sd_configs:
      - host: unix:///var/run/docker.sock
        refresh_interval: 5s
    relabel_configs:
      # Keep only Smart City containers
      - source_labels: [__meta_docker_container_name]
        regex: 'smart-city-.*'
        action: keep
      # Add container name as label
      - source_labels: [__meta_docker_container_name]
        target_label: container
      - source_labels: [__meta_docker_container_name]
        target_label: job
        replacement: ${1}
      # Add image as label
      - source_labels: [__meta_docker_container_image]
        target_label: image
      # Add service label from container name
      - source_labels: [__meta_docker_container_name]
        regex: 'smart-city-(.*)'
        target_label: service
        replacement: '${1}'
