Add practical examples to multiple files

- LF9-03 Virtualisierung: Docker Compose + Volume examples
- LF6-02 Frontend: To-Do list practical example
- LF8-04 ETL: Complete ETL pipeline example
- LF6-04 Sicherheit: Express.js security headers
- LF2-04 Nutzwertanalyse: Cloud provider selection example
- LF9-04 Monitoring: Prometheus alerts + Python logging
This commit is contained in:
2026-03-13 12:01:15 +01:00
parent eb4a13ef7c
commit 7df533c7a2
7 changed files with 331 additions and 7 deletions

View File

@@ -61,6 +61,73 @@ scrape_configs:
- targets: ['localhost:9100']
```
### Praktisches Beispiel: Alert-Regeln
```yaml
# alerts.yml
groups:
- name: server_alerts
rules:
# Hohe CPU-Auslastung
- alert: HighCPU
expr: 100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: warning
annotations:
summary: "Hohe CPU-Auslastung auf {{ $labels.instance }}"
description: "CPU Auslastung ist seit 5 Minuten über 80%"
# Wenig Speicherplatz
- alert: DiskSpaceLow
expr: (node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"}) * 100 < 10
for: 2m
labels:
severity: critical
annotations:
summary: "Wenig Speicherplatz auf {{ $labels.instance }}"
# Service ausgefallen
- alert: ServiceDown
expr: up == 0
for: 1m
labels:
severity: critical
annotations:
summary: "{{ $labels.job }} Service ausgefallen"
```
### Praktisches Beispiel: Python Logging
```python
import logging
import logging.handlers
import sys
# Logger konfigurieren
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler(sys.stdout),
logging.handlers.RotatingFileHandler(
'app.log',
maxBytes=10_000_000, # 10 MB
backupCount=5
)
]
)
logger = logging.getLogger(__name__)
# Log-Ebenen nutzen
logger.debug("Detaillierte Debug-Info")
logger.info("Anwendung gestartet")
logger.warning("Warnung: Konfiguration fehlt")
logger.error("Fehler: Datenbank nicht erreichbar")
logger.critical("Kritisch: System muss heruntergefahren werden")
```
### Grafana Dashboard
```