Prefect
URL: http://109.199.120.120:4200 Config:/opt/coderz/configs/prefect/flows/
Prefect is a workflow orchestration platform that runs automated background jobs on schedules. In the Coderz Stack, it replaces manual operational tasks — health checks, alerting, reporting, and cleanup — with automated, monitored, and logged flows.
What Is a Prefect Flow?
A flow is a Python function decorated with@flow. It contains tasks that run in sequence or parallel. Prefect:
- Schedules flows on cron schedules
- Retries failed tasks automatically
- Logs every run with stdout/stderr
- Sends notifications on failure
- Provides a UI to monitor all runs
Deployed Flows
| Flow | Schedule | Description | On Failure |
|---|---|---|---|
system-health-check | Every 5 min | Check CPU, RAM, disk, process counts | Log |
services-health-check | Every 10 min | HTTP health check all stack services | Email alert |
threshold-alert-check | Every 15 min | Alert if CPU > 80%, RAM > 85%, Disk > 90% | Email alert |
docker-restart-monitor | Every 10 min | Detect containers with restart loops or unhealthy status | Email alert |
k8s-health-check | Every 15 min | Check k3s pods, nodes, deployments | Email alert |
daily-summary-report | Daily 06:00 UTC | Full stack health summary report | Email report |
weekly-cleanup-report | Sunday 02:00 UTC | Disk cleanup, Docker prune, old log removal | Email report |
Flow Detail: system-health-check
Runs every 5 minutes. Checks:- CPU usage (via
/proc/stat) - RAM usage (via
/proc/meminfo) - Disk usage (via
df) - Docker container count (via Docker socket)
Flow Detail: services-health-check
Runs every 10 minutes. Sends HTTP GET to each service:Flow Detail: threshold-alert-check
Runs every 15 minutes. Checks actual metric values:Flow Detail: docker-restart-monitor
Runs every 10 minutes. Checks:- Containers with
RestartCount > 3in the last hour - Containers with health status
unhealthy
Flow Detail: daily-summary-report
Runs daily at 06:00 UTC. Email contains:- Server uptime
- Current CPU / RAM / Disk usage
- All service health status (UP/DOWN)
- Prefect flow run summary (success/failure counts)
- Docker container status
- k3s pod status
Flow Detail: weekly-cleanup-report
Runs Sunday 02:00 UTC. Performs:docker system prune -f(removes unused images, stopped containers, unused networks)- Deletes Elasticsearch indices older than 30 days
- Truncates old Loki chunks
- Reports disk space freed
Email Notifications
All flows send emails via Postfix SMTP relay → Gmail:- SMTP Host:
host.docker.internal:25 - From:
alerts@coderz.local - To:
aboodm7med1995@gmail.com
Prefect UI
Access at http://109.199.120.120:4200| Section | What You See |
|---|---|
| Flow Runs | History of every run — success/failure/pending |
| Flows | All registered flows |
| Deployments | Schedules and next run times |
| Work Pools | Where flows execute |
| Logs | Full stdout/stderr for each run |
Flow Files
- Add a
@flowfunction tosample_flows.py - Add a deployment to
prefect.yaml - Restart the Prefect worker:
docker compose restart prefect-worker