Skip to content

Grafana | Loki | Promtail

docker-compose.yml

YAML
version: '3.8'

services:

  grafana:
    image: grafana/grafana:latest
#    ports:
#      - 3000:3000
    user: "1000"
    volumes:
      - ./config/grafana-datasources.yml:/etc/grafana/provisioning/datasources/datasources.yaml
      - ./grafana_data:/var/lib/grafana
    environment:
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
      - GF_AUTH_DISABLE_LOGIN_FORM=true
    networks:
      - ubuntu_default

  loki:
    image: grafana/loki:latest
#    ports:
#      - 3100:3100
    labels: [app=promtail]
    command: -config.file=/etc/loki/local-config.yaml
    volumes:
      - ./config/loki-config.yaml:/etc/loki/local-config.yaml
      - ./loki-data:/loki
    user: "1000"
    networks:
      - ubuntu_default

  promtail:
    image:  grafana/promtail:latest
    container_name: promtail
    volumes:
      - ./config/prom-config.yaml:/etc/promtail/config.yml
      - ./config/promtail.yaml:/etc/promtail/docker-config.yaml
      - /var/lib/docker/containers:/var/lib/docker/containers:ro
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/log:/var/log
    command: -config.file=/etc/promtail/docker-config.yaml
    depends_on:
      - loki
    networks:
      - ubuntu_default

  tester:
    container_name: nginx-test
    image: nginx
    labels:
      logging: "promtail"
      logging_jobname: "nginx-test"
    networks:
      - ubuntu_default


networks:
  ubuntu_default:
    name: ubuntu_default
    external: true

config/grafana-datasources.yml

YAML
apiVersion: 1

datasources:
  - name: Loki
    type: loki
    access: proxy
    url: http://loki:3100
    version: 1
    editable: false
    isDefault: true

config/loki-config.yaml

YAML
auth_enabled: false

server:
  http_listen_port: 3100

common:
  instance_addr: localhost
  path_prefix: /loki
  storage:
    filesystem:
      chunks_directory: /loki/chunks
      rules_directory: /loki/rules
  replication_factor: 1
  ring:
    kvstore:
      store: inmemory

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

# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
#
# Statistics help us better understand how Loki is used, and they show us performance
# levels for most users. This helps us prioritize features and documentation.
# For more information on what's sent, look at
# https://github.com/grafana/loki/blob/main/pkg/usagestats/stats.go
# Refer to the buildReport method to see what goes into a report.
#
# If you would like to disable reporting, uncomment the following lines:
analytics:
  reporting_enabled: false

config/prom-config.yaml

YAML
server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml

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

scrape_configs:
  - job_name: syslog
    pipeline_stages:
      - regex:
          expression: '^(?P<timestamp>\S+\s+\S+)\s+(?P<process>\S+)\[(?P<pid>\d+)\]:\s+(?P<message>.*)'
    static_configs:
      - targets:
          - localhost
        labels:
          job: local-syslog
          __path__: /var/log/syslog