MGCJ Labs · Free lesson

Free Linux Health Lab

MGCJ Labs · Version 1.0.0 · Project 01 from the DevOps Job-Ready Project Kit

Build a Linux health check you can run, test and explain. This free lesson includes the same monitor and six unit tests shipped in the paid kit, with a standalone guide and a learning-notes template.

You will read disk and memory usage, trigger a safe warning, understand exit codes, run tests and make one improvement. The monitor reads local metrics; it does not change settings, start servers or send data anywhere.

1. Open the right terminal

You need: Ubuntu Linux or Ubuntu in Windows Subsystem for Linux (WSL2), Python 3.10 or newer, and a text editor. No Python packages, Docker, GitHub account, Terraform or AWS account are needed for this lesson. Internet is needed only for installation/downloads. Once extracted, the lesson runs offline.

Windows, if Ubuntu is not installed: open PowerShell as Administrator and run:

wsl --install -d Ubuntu

Restart Windows if prompted, then open Ubuntu from the Start menu. On first launch, create your Linux username and password. All remaining commands go in the Ubuntu terminal, not PowerShell or Command Prompt. If Ubuntu already opens, skip the installation command.

Ubuntu, including WSL — any folder: check Python:

python3 --version

You should see Python 3.10 or newer. To install Python and the terminal download tool using Ubuntu's package manager, run this only if you need them:

sudo apt-get update
sudo apt-get install -y python3 curl

sudo asks for your Linux password; typing it does not display characters. These commands install software on your computer. Running the lesson itself does not require sudo.

2. Put the lesson in its own folder

Choose A or B, not both. Each makes a new folder under ~/projects, so an existing project is not overwritten. Keep this Ubuntu terminal open while working through the lesson.

A. Download directly in the Ubuntu terminal

Where: Ubuntu terminal, any folder. Paste this complete block. It downloads only the free lesson, extracts it, then verifies the included files against their checksum manifest.

mkdir -p "$HOME/projects"
lab_parent="$(mktemp -d "$HOME/projects/mgcj-free-health.XXXXXX")"
if curl --fail --location --silent --show-error \
  'https://mgcjlabs.com/downloads/MGCJ-Labs-Free-Linux-Health-Lab-v1.0.0.zip' \
  --output "$lab_parent/free-lab.zip" &&
  python3 -m zipfile -e "$lab_parent/free-lab.zip" "$lab_parent" &&
  cd "$lab_parent/mgcj-free-linux-health-lab" &&
  sha256sum --check --quiet CONTENTS.sha256; then
  export LAB_ROOT="$PWD"
  printf 'Files verified. Your lab folder: %s\n' "$LAB_ROOT"
else
  printf 'Setup did not finish. Stop here and read the error above.\n' >&2
fi

Success: Files verified. Your lab folder: ... appears. The included manifest detects changed or damaged packaged files; it is not a publisher signature. The ZIP checksum is also published on the download page if you want to compare the downloaded archive itself.

LAB_ROOT remembers your extracted folder for later commands. Copy the displayed path into your notes. In a new Ubuntu terminal, restore it with export LAB_ROOT='/home/YOUR_LINUX_NAME/projects/mgcj-free-health.XXXXXX/mgcj-free-linux-health-lab', using your actual saved path.

B. Use a ZIP already downloaded in your browser

Where: Ubuntu terminal, any folder. The prompt asks for the full path to the ZIP, not its containing folder.

read -r -p 'Full ZIP path (WSL: /mnt/c/Users/YOUR_NAME/Downloads/MGCJ-Labs-Free-Linux-Health-Lab-v1.0.0.zip; use / and no quotes): ' lab_zip
if [ -f "$lab_zip" ]; then
  mkdir -p "$HOME/projects"
  lab_parent="$(mktemp -d "$HOME/projects/mgcj-free-health.XXXXXX")"
  if python3 -m zipfile -e "$lab_zip" "$lab_parent" &&
    cd "$lab_parent/mgcj-free-linux-health-lab" &&
    sha256sum --check --quiet CONTENTS.sha256; then
    export LAB_ROOT="$PWD"
    printf 'Files verified. Your lab folder: %s\n' "$LAB_ROOT"
  else
    printf 'Extraction or file verification failed. Stop here.\n' >&2
  fi
else
  printf 'ZIP not found: %s\nUse the full Linux/WSL path shown in the prompt.\n' "$lab_zip" >&2
fi

Success: the folder path is printed. Save it. The extraction command uses Python's built-in ZIP support; there is no separate unzip package to install. Checksums should match before you edit files. After making your own changes, use tests rather than expecting the original checksum to match.

3. Run a real health check

Where: the same Ubuntu terminal. Each block below starts by moving into your lab folder. :? stops the command if LAB_ROOT has not been set.

cd "${LAB_ROOT:?Set LAB_ROOT to your extracted lab folder first}"
lab_exit=0
python3 project-01-linux-health/health_check.py || lab_exit=$?
printf 'Monitor exit code: %s\n' "$lab_exit"

What it does: reads disk usage for / and available memory from Linux /proc/meminfo, compares them with the default 85% warning thresholds, and prints JSON.

Read these fields:

Success: JSON appears and the printed exit code is 0 or 2. Your actual percentages vary. In WSL, memory describes the Linux environment and / is its root filesystem; these are not a complete Windows Task Manager report.

Exit codes communicate with other programs: 0 = OK, 2 = WARN, 3 = metric-read error. Invalid arguments also make Python's argument parser return 2, so inspect the output as well as the code. || lab_exit=$? preserves a nonzero result so the terminal can print it.

4. Trigger an alert safely

Where: Ubuntu terminal, lab folder. Predict the result before running:

cd "${LAB_ROOT:?Set LAB_ROOT first}"
lab_exit=0
python3 project-01-linux-health/health_check.py --disk-warning 0 || lab_exit=$?
printf 'Monitor exit code: %s\n' "$lab_exit"

Expected: status is WARN, warnings includes disk, and the exit code is 2. Memory may also warn depending on your computer. You lowered a threshold for this run; you did not fill the disk or modify the source.

Now inspect the available options:

cd "${LAB_ROOT:?Set LAB_ROOT first}"
python3 project-01-linux-health/health_check.py --help

Try --memory-warning 75 instead of --disk-warning 0 in the previous block. Explain why a lower threshold can produce more warnings. In WSL, try --disk-path /mnt/c to inspect the mounted Windows C: filesystem.

5. Run the six tests

Where: Ubuntu terminal, lab folder.

cd "${LAB_ROOT:?Set LAB_ROOT first}"
python3 -m unittest discover -s project-01-linux-health -p 'test_*.py' -v

Expected: Ran 6 tests followed by OK (timing varies). These tests use fixed inputs and mocked disk/memory readings, so a busy computer should not fail them. They check the memory calculation, healthy and warning states, the warning exit code, invalid memory values and equality at the threshold.

Open project-01-linux-health/test_health_check.py in your editor. Find test_warning_on_threshold_boundary: a reading of 85 with a threshold of 85 is already a warning. Explain how changing >= to > in the monitor would change that result.

6. Improve the monitor yourself

Where: your editor for changes; the Ubuntu terminal for tests. Keep the default JSON output working.

Open project-01-linux-health/health_check.py. Follow main() to inspect() and then memory_used_percent() so you can describe how a command becomes a report.

Assignment: add a --status-only flag. This is an exercise, not a feature already provided. With the flag, print only OK or WARN; without it, keep the JSON. Preserve exit codes 0 and 2, and the existing error behavior.

Suggested approach:

  1. Add an argparse boolean flag in main().
  2. Choose the print format after the report is created; keep the return-code logic.
  3. Add controlled tests for healthy status-only output, warning output/exit code, and unchanged default JSON output.
  4. Rerun step 5. Then run your new flag with --disk-warning 0 and check that it prints WARN and returns 2.

Further learning: add a missing-memory-field test; compare / and /mnt/c; or explain how a scheduled monitor should distinguish warnings from metric-read failures. Change one thing at a time. Document the test that would fail without your change.

7. Keep evidence you can explain

Where: Ubuntu terminal, lab folder. This saves a warning report and its exit code in your local evidence folder.

cd "${LAB_ROOT:?Set LAB_ROOT first}"
mkdir -p evidence
lab_exit=0
python3 project-01-linux-health/health_check.py --disk-warning 0 > evidence/warning.json || lab_exit=$?
printf '%s\n' "$lab_exit" > evidence/warning-exit-code.txt
cat evidence/warning.json
printf 'Saved exit code: %s\n' "$lab_exit"

Fill in LEARNING_NOTES.md in your editor: what you ran, why the warning occurred, your improvement and what the tests prove. Review or remove your hostname and personal paths before sharing output.

You are finished when you can demonstrate the warning, pass the tests and explain your tested change. The monitor exits after each run, so there are no servers, containers or cloud resources to shut down.

Continue with the complete kit

This is one complete introductory lesson. The DevOps Job-Ready Project Kit is $25 USD once and includes this project plus four more: a Dockerized health API, GitHub Actions CI, a local Terraform service inventory, and a blue/green release-and-rollback capstone. It also includes the full offline handbook, portfolio templates and exercises, and 90 days of written setup support and released bug-fix updates.

Explore the full kit: https://mgcjlabs.com/devops-job-ready-kit?utm_source=free_lab

The free lab is yours to keep. No purchase is required to finish it. Read LICENSE.md for the free-sample permissions. Send feedback to mgcjlabs@gmail.com; the free sample does not include the paid kit's support entitlement. These projects support learning and do not guarantee employment.

The instructions above contain the commands you need; no manual installer downloads are required. Command references: