stacks/monitoring/loki/promtail.yaml

# stacks/monitoring/loki/promtail.yaml
# Picks up docker json-file logs plus a few host log files.

server:
  http_listen_port: 9080
  grpc_listen_port: 0
  log_level: warn

positions:
  filename: /tmp/positions.yaml

clients:
  - url: http://loki:3100/loki/api/v1/push
    backoff_config:
      min_period: 1s
      max_period: 30s
      max_retries: 10

scrape_configs:
  - job_name: docker
    docker_sd_configs:
      - host: unix:///var/run/docker.sock
        refresh_interval: 15s
    relabel_configs:
      - source_labels: ['__meta_docker_container_name']
        regex: '/(.*)'
        target_label: container
      - source_labels: ['__meta_docker_container_label_com_docker_compose_service']
        target_label: service
      - source_labels: ['__meta_docker_container_label_com_docker_compose_project']
        target_label: stack
      - target_label: host
        replacement: homelab-1
    pipeline_stages:
      - docker: {}
      - match:
          selector: '{service="caddy"}'
          stages:
            - json:
                expressions:
                  status: status
                  method: request.method
                  host: request.host
                  uri: request.uri
                  duration: duration
            - labels:
                status:
                method:
                host:

  - job_name: syslog-host
    static_configs:
      - targets: [localhost]
        labels:
          job: syslog
          host: homelab-1
          __path__: /var/log/syslog
    pipeline_stages:
      - regex:
          expression: '^(?P<ts>\S+ \S+ \S+) (?P<host>\S+) (?P<process>[^:]+): (?P<msg>.*)$'
      - labels:
          process:
      - timestamp:
          source: ts
          format: 'Jan 2 15:04:05'

  - job_name: kern
    static_configs:
      - targets: [localhost]
        labels:
          job: kern
          __path__: /var/log/kern.log

  - job_name: smart
    static_configs:
      - targets: [localhost]
        labels:
          job: smart
          __path__: /var/log/smartd.log