Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Local Micro-Cloud & Monitoring Engine

A lightweight, native Linux process manager & monitoring engine — built entirely in Bash.

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.


Architecture Overview

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.


Key Technical Features

  • Modular design — Each concern (core utilities, provisioning, monitoring, alerting) lives in its own file under lib/, sourced by a slim cloud.sh entry 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 $! and disowned so they survive independently of the launching shell's job control.
  • Text-based DB with duplicate guardsstorage/status.db is a strict CSV (NAME,PID,CPU_LIMIT,MEM_LIMIT,STATUS) manipulated with grep/awk/read. db_add_service() rejects duplicate service names before writing.
  • Live monitoring using native ps parsingcheck_resource_usage() queries ps -p <pid> -o %cpu=,%mem= per tracked PID, robustly stripping headers/whitespace so short-lived or idle processes parse cleanly.
  • Decimal comparison via awk exit codes — Bash cannot natively compare floating-point numbers (0.5 > 40 fails in [[ ]]). Threshold breaches are detected with:
    awk -v actual="$cpu_pct" -v limit="$cpu_limit" 'BEGIN { exit !(actual > limit) }'
    letting awk do 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 webhookssend_alert_notification() dispatches a curl POST to a configurable WEBHOOK_URL and logs a [WEBHOOK] Simulating Alert Dispatch to Slack/Discord line, making it trivial to swap in a real Slack/Discord endpoint later.

How to Install & Use

Requirements

  • Bash 4+ (Linux / WSL)
  • Standard coreutils: ps, awk, sed, grep, curl

Setup

git clone <your-repo-url>
cd micro-cloud
chmod +x cloud.sh

Deploy a service

./cloud.sh deploy --name backend --cpu 40 --mem 128M

List registered services

./cloud.sh list
NAME                 PID      CPU_LIMIT  MEM_LIMIT  STATUS
backend              4183     40         128M       RUNNING

Run the live monitoring loop

./cloud.sh monitor

Polls 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.

Trigger a stress test

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!

Clear all service records

./cloud.sh clear

Configuration

All 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

License

This project is provided as-is for educational and portfolio purposes.

About

A lightweight, native Linux process manager and monitoring engine built from scratch with AI. Created purely for fun and curiosity to see how Docker-like orchestration works under the hood using native Bash utilities.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages