Promtail is an agent that ships logs from local files to Loki. It's the log collector in this observability stack, tailing log files from Django and sending them to Loki for storage and querying.
Description
Promtail is a lightweight agent that:
- Tails log files (continuously reads new lines)
- Parses and processes log lines
- Adds labels for easy querying
- Pushes logs to Loki via HTTP
In this stack, Promtail:
- Tails Django application logs
- Tails Gunicorn access and error logs
- Parses JSON log format
- Extracts labels (level, logger)
- Pushes to Loki automatically
Note: You don't need to manually push logs! Promtail handles everything automatically.
The Promtail configuration defines:
- Server settings (port)
- Position tracking (remembers where it left off)
- Where to send logs (Loki endpoint)
- What files to watch and how to parse them
# =============================================================================# SERVER SETTINGS# =============================================================================server:http_listen_port:9080# Port for metrics endpointgrpc_listen_port:0# Disable gRPC (not needed)# =============================================================================# POSITION TRACKING# =============================================================================positions:filename:/tmp/positions.yaml# File to store read positions# =============================================================================# CLIENT CONFIGURATION# =============================================================================clients:-url:http://obs-loki:3100/loki/api/v1/push# Loki push endpoint# =============================================================================# SCRAPE CONFIGURATIONS# =============================================================================scrape_configs:# ===========================================================================# JOB 1: Django Application Logs (JSON Format)# ===========================================================================-job_name:django# Job namestatic_configs:-targets:-localhost# Required but ignored for file watchinglabels:app:django# Label: app=djangoenv:dev# Label: env=dev__path__:/var/log/django/django.log# File to watchpipeline_stages:-json:# Parse as JSONexpressions:level:levelname# Extract "levelname" β "level" labellogger:name# Extract "name" β "logger" labelmessage:message# Extract "message" β log line-labels:# Convert to Loki labelslevel:logger:# ===========================================================================# JOB 2: Gunicorn Access Logs# ===========================================================================-job_name:gunicorn_accessstatic_configs:-targets:-localhostlabels:app:djangolog_type:accessenv:dev__path__:/var/log/django/access.log# ===========================================================================# JOB 3: Gunicorn Error Logs# ===========================================================================-job_name:gunicorn_errorstatic_configs:-targets:-localhostlabels:app:djangolog_type:errorlevel:ERRORenv:dev__path__:/var/log/django/error.log