This setup provides centralized logging using the Grafana stack:
- Loki: Log aggregation system
- Promtail: Log collector and forwarder
- Grafana: Visualization and querying interface
Copy the example environment file and set your credentials:
cp .env.example .env
Edit .env
file to set your credentials:
GRAFANA_USER=your_username
GRAFANA_PASSWORD=your_secure_password
Run the setup script to create necessary directories:
./setup.sh
Or manually create the directories:
# Create Loki data directories
mkdir -p loki-data/{wal,index,chunks,compactor,boltdb-cache}
chmod -R 777 loki-data
docker-compose up -d
- Open
http://localhost:3200
in your browser - Login with the credentials you set in
.env
Edit promtail-config.yaml
to add new log sources. Example structure:
scrape_configs:
- job_name: new_log_source
static_configs:
- targets:
- localhost
labels:
job: application_name
app: service_name
__path__: /path/to/your/logs/*.log
job_name
: Unique identifier for this log sourcelabels
: Add relevant labels to help query logsjob
: Type of application/serviceapp
: Specific application name
__path__
: Path to log files (supports wildcards)
After adding new sources:
docker-compose restart promtail
In Grafana:
- Go to Explore (Compass icon)
- Select "Loki" datasource
- Use LogQL to query logs:
{app="medzi_app"}
: All logs from medzi app{job="medzi_application"}
: All application logs{app="medzi_app"} |= "error"
: All error logs
.
├── docker-compose.yaml
├── loki-config.yaml
├── promtail-config.yaml
├── setup.sh
└── loki-data/
├── wal/
├── index/
├── chunks/
├── compactor/
└── boltdb-cache/
- Grafana:
3200
(Web Interface) - Loki:
3100
(API Endpoint)
And here's the setup script:
```bash:setup.sh
#!/bin/bash
# Create Loki data directories
echo "Creating Loki data directories..."
mkdir -p loki-data/{wal,index,chunks,compactor,boltdb-cache}
chmod -R 777 loki-data
echo "Setup complete! You can now run: docker-compose up -d"
Don't forget to make the script executable:
chmod +x setup.sh
This README provides:
- Step-by-step setup instructions
- How to add new log sources
- Basic querying information
- Directory structure explanation
- Port information
The setup script automates the directory creation process, making it easier to get started.