Dokploy: Monitoring, Backup, dan Best Practices
Kelola aplikasi production dengan monitoring dan disaster recovery
Tujuan Pembelajaran
- Bisa monitor aplikasi dan resource usage
- Mengerti log management
- Bisa setup backup dan recovery
Analogi
Production Checklist:
├── Monitoring (CPU, memory, disk)
├── Log aggregation
├── Database backups
├── SSL certificate renewal
├── Health checks
└── Multi-server setup
Production readiness membutuhkan monitoring, logging, dan backup strategy
Penjelasan Konsep
Aplikasi sudah deploy, tapi itu baru setengah perjalanan. Untuk production yang reliable, kamu butuh monitoring, logging, backup, dan disaster recovery plan.
Monitoring di Dokploy
Dokploy punya built-in monitoring dashboard:
- Container Stats: CPU, memory, network usage per container
- Server Metrics: Overall VPS resource usage
- Application Logs: Real-time log streaming
- Deployment History: Riwayat deploy dan status
Akses monitoring dari dashboard → Application → Monitoring/Logs.
Log Management
Logs penting untuk debugging dan audit:
- Application Logs: Stdout/stderr dari container, viewable di dashboard
- Access Logs: Traefik access logs untuk HTTP requests
- Error Tracking: Integrasi dengan Sentry atau similar
Best practice: Jangan log sensitive data (password, token, PII). Gunakan structured logging (JSON format) untuk easier parsing.
Database Backup
Backup adalah asuransi data. Strategi untuk PostgreSQL:
-
Dokploy automated backups: Enable di database settings
-
Manual pg_dump:
docker exec postgres-container pg_dump -U postgres app > backup.sql -
Scheduled backups dengan cron:
Backup harian
0 2 * * * docker exec postgres pg_dump -U postgres app | gzip > /backups/app-$(date +%Y%m%d).sql.gz
### SSL Certificate Renewal
Let's Encrypt certificates berlaku 90 hari.
Dokploy otomatis renew, tapi periksa status secara berkala:
```bash
# Cek certificate expiry
echo | openssl s_client -servername yourdomain.com -connect yourdomain.com:443 2>/dev/null | openssl x509 -noout -dates
Health Checks
Tambahkan health check endpoint di aplikasi:
app.get('/health',
(c) => {
// Cek database connection
// Cek external services
return c.json({ status: 'ok', timestamp: new Date().toISOString() });
});
Konfigurasi health check di Dokploy untuk auto-restart kalau aplikasi unhealthy.
Security Best Practices
- Jangan expose database ports: Gunakan internal Docker network
- Gunakan secrets untuk sensitive data: Jangan hardcode credentials
- Keep images updated: Regularly update base images
- Enable firewall: UFW atau cloud firewall, hanya buka port yang perlu
- Regular security updates: apt update && apt upgrade
Multi-Server (Cluster)
Untuk high availability, Dokploy support multi-server:
- Tambahkan worker nodes di Dokploy settings
- Deploy aplikasi ke multiple servers
- Traefik melakukan load balancing
Disaster Recovery Plan
- Backup database: daily automated + manual before major changes
- Source code: Git repository (sudah ada)
- Environment variables: Export dari Dokploy dashboard
- Dokumentasi: Runbook untuk recovery steps
Contoh Kode
# Health check endpoint
# src/routes/health.ts
import { Hono } from 'hono';
import { db } from '../db';
import { redis } from '../redis';
const health = new Hono();
health.get('/', async (c) => {
const checks = {
timestamp: new Date().toISOString(),
uptime: process.uptime(),
checks: {} as Record<string, string>,
};
// Database check
try {
await db.execute(sql`SELECT 1`);
checks.checks.database = 'ok';
} catch (err) {
checks.checks.database = 'error';
}
// Redis check
try {
await redis.ping();
checks.checks.redis = 'ok';
} catch (err) {
checks.checks.redis = 'error';
}
const allOk = Object.values(checks.checks).every(v => v === 'ok');
return c.json(checks, allOk ? 200 : 503);
});
export default health;
# Backup script
#!/bin/bash
# backup.sh - Jalankan di server via cron
BACKUP_DIR="/var/backups/app"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
# Backup PostgreSQL
docker exec postgres pg_dump -U postgres app | gzip > $BACKUP_DIR/db_$DATE.sql.gz
# Backup Redis
docker exec redis redis-cli BGSAVE
docker cp redis:/data/dump.rdb $BACKUP_DIR/redis_$DATE.rdb
# Hapus backup lama (keep 7 days)
find $BACKUP_DIR -type f -mtime +7 -delete
echo "Backup completed: $DATE"Penjelasan Kode
Prompt AI
Setup health check endpoint dan scheduled backup. Configure alerting (email/Slack) untuk notification saat service down.
Pertanyaan Reflektif
Dokumen disaster recovery plan-mu: langkah-langkah restore dari backup, RTO (Recovery Time Objective), dan RPO (Recovery Point Objective).