micro-cloud provisions real background processes, tracks them in a
text-based state database, monitors their live CPU/RAM usage with native
Linux utilities, and fires alerts (log files + simulated webhooks) when a
service breaches its configured resource limits. No daemons, no external
dependencies, no runtimes — just Bash and the Linux process model.
micro-cloud/
├── cloud.sh # Main entry point & CLI argument parser
├── config/
│ └── global.conf # Global thresholds, intervals, and paths
├── lib/
│ ├── core.sh # Shared utilities: colored logging (log)
│ ├── provisioner.sh # DB read/write, service deployment, stress mode
│ ├── monitor.sh # Live resource sampling & threshold checks
│ └── notifier.sh # Alert logging & simulated webhook dispatch
└── storage/
├── status.db # CSV state DB: NAME,PID,CPU_LIMIT,MEM_LIMIT,STATUS
└── logs/
└── alerts.log # Persisted alert history (generated at runtime)
Every module is sourced dynamically from cloud.sh using
$(dirname "${BASH_SOURCE[0]}"), so the tool runs correctly regardless of
the caller's current working directory.
- Modular design — Each concern (core utilities, provisioning,
monitoring, alerting) lives in its own file under
lib/, sourced by a slimcloud.shentry point. No giant single-file scripts. - Real background provisioning via
disown— Services are spawned as genuine background jobs (sleep 9999d &or a CPU-burning loop for--stress), with their real PID captured via$!anddisowned so they survive independently of the launching shell's job control. - Text-based DB with duplicate guards —
storage/status.dbis a strict CSV (NAME,PID,CPU_LIMIT,MEM_LIMIT,STATUS) manipulated withgrep/awk/read.db_add_service()rejects duplicate service names before writing. - Live monitoring using native
psparsing —check_resource_usage()queriesps -p <pid> -o %cpu=,%mem=per tracked PID, robustly stripping headers/whitespace so short-lived or idle processes parse cleanly. - Decimal comparison via
awkexit codes — Bash cannot natively compare floating-point numbers (0.5 > 40fails in[[ ]]). Threshold breaches are detected with:lettingawk -v actual="$cpu_pct" -v limit="$cpu_limit" 'BEGIN { exit !(actual > limit) }'
awkdo the float math and reporting the result through its exit status. - Log rotation-friendly alerts — Every breach is appended as a
timestamped line to
storage/logs/alerts.log, independent of the live terminal output, so alert history persists across monitoring sessions. - Simulated webhooks —
send_alert_notification()dispatches acurlPOST to a configurableWEBHOOK_URLand logs a[WEBHOOK] Simulating Alert Dispatch to Slack/Discordline, making it trivial to swap in a real Slack/Discord endpoint later.
- Bash 4+ (Linux / WSL)
- Standard coreutils:
ps,awk,sed,grep,curl
git clone <your-repo-url>
cd micro-cloud
chmod +x cloud.sh./cloud.sh deploy --name backend --cpu 40 --mem 128M./cloud.sh listNAME PID CPU_LIMIT MEM_LIMIT STATUS
backend 4183 40 128M RUNNING
./cloud.sh monitorPolls every MONITOR_INTERVAL seconds (configured in config/global.conf),
printing live CPU/MEM readings and firing alerts on threshold breaches.
Press Ctrl+C to stop.
Deploy a service with a strict CPU limit and the --stress flag to spawn a
real CPU-burning background loop, then watch the monitor detect and alert
on the breach:
./cloud.sh deploy --name high-load-app --cpu 10 --mem 128M --stress
./cloud.sh monitor[INFO] Monitoring high-load-app (PID 4183): CPU: 100%, MEM: 0.0%
[CRITICAL] Service 'high-load-app' (PID 4183) breached resource limits -- CPU: 100% (limit 10%), MEM: 0.0% (limit 128M)
[INFO] [WEBHOOK] Simulating Alert Dispatch to Slack/Discord: Service high-load-app breached CPU/MEM limits!
./cloud.sh clearAll tunables live in config/global.conf:
| Variable | Description | Default |
|---|---|---|
CPU_THRESHOLD |
Global CPU alert threshold (%) | 80 |
MEM_THRESHOLD |
Global memory alert threshold (%) | 80 |
MONITOR_INTERVAL |
Seconds between monitoring loop iterations | 10 |
WEBHOOK_URL |
Endpoint for simulated webhook dispatch | (empty) |
LOG_DIR |
Directory for persisted alert logs | storage/logs |
This project is provided as-is for educational and portfolio purposes.