A health monitor that only ever prints OK is hard to trust. Before relying on it, you need to see its warning path and understand what another program receives when that happens.

You can test that path without filling your disk: lower the warning threshold for one run.

This walkthrough uses a small Python monitor from my free Linux Health Lab. It reads disk and memory usage, prints JSON, and returns an exit code. The code uses the standard library and runs locally on Ubuntu or Ubuntu in WSL2, with Python 3.10+. No AWS account or Python packages are needed.

1. Get the runnable sample

Download the free lesson and source code. No email signup or payment is required. The ZIP includes the monitor, six unit tests, and an offline guide.

Open an Ubuntu terminal. On Windows, use the Ubuntu terminal in WSL2 for the commands below. Check your Python version:

python3 --version 

After extracting the ZIP, change into its mgcj-free-linux-health-lab folder. The complete setup guide includes download, extraction, checksum verification, and Windows-to-WSL path examples.

All subsequent commands run from that extracted folder.

2. Read the normal report

lab_exit=0 python3 project-01-linux-health/health_check.py || lab_exit=$? printf 'Monitor exit code: %s\n' "$lab_exit" 

The monitor measures the selected filesystem (by default, /) and reads MemTotal and MemAvailable from Linux's /proc/meminfo. Its memory calculation is:

round((total - available) / total * 100, 1) 

Using available memory matters: memory Linux can reclaim is useful capacity, even when it is not completely unused.

The JSON includes the disk and memory percentages, timestamp, hostname, status, and a list of warnings. The default warning threshold is 85% for each metric. Your machine may already exceed a threshold, so a normal run can legitimately report either OK or WARN.

In WSL, these readings describe the Linux environment. They are not a complete Windows Task Manager report. You can select the mounted C: filesystem with --disk-path /mnt/c.

3. Trigger a warning safely

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

Expect status to be WARN, the warnings list to include disk, and the exit code to be 2. Memory may also warn, depending on your machine.

This works because the comparison in the monitor is:

if disk_percent >= disk_warning: warnings.append('disk') 

A valid disk percentage is at least zero. Setting the threshold to zero therefore exercises the warning branch. It changes the threshold for this invocation; it does not fill your disk or edit the source.

This checks the real metric-reading and reporting path with an easy-to-trigger condition. It does not prove that every operational failure is handled. Controlled tests cover different questions.

4. Read JSON and exit status together

The monitor uses these exit codes:

Code Meaning
0 Metrics read successfully; no warnings
2 Metrics read successfully; a threshold was reached
3 A metric could not be read or validated

There is one wrinkle: Python's argument parser also exits with 2 for invalid arguments. A code of 2 alone is therefore insufficient to identify a health warning. Check that the output is a valid health report and inspect its status and warnings fields. Argument errors produce usage/error text instead.

The shell pattern above initializes lab_exit to zero and captures a nonzero result immediately with || lab_exit=$?. If you run another command before saving $?, you can accidentally read that command's status instead.

5. Test the boundary, not just the obvious failure

Run the included tests:

python3 -m unittest discover -s project-01-linux-health -p 'test_*.py' -v 

The expected result is six tests followed by OK. They use fixed inputs and mocked metric readings, so your actual disk usage should not determine whether they pass.

Open project-01-linux-health/test_health_check.py and find test_warning_on_threshold_boundary. It supplies disk and memory readings of exactly 85 with the default thresholds of 85. Both must warn.

Changing >= to > would make that test fail: equality would no longer trigger a warning. That small test records a precise behavior that a vague “it detects high usage” check can miss.

The other tests cover the memory calculation, healthy output, warnings, warning exit status, and invalid memory statistics. They do not establish continuous monitoring or production readiness.

6. Make one tested improvement

Try adding a --status-only flag that prints just OK or WARN while preserving the existing exit codes. This is an exercise; the downloaded monitor does not already implement the flag.

Add tests for healthy status-only output, warning output with exit code 2, and unchanged JSON output when the flag is absent. Keep the metric-error behavior intact.

Before sharing evidence, review the JSON for your hostname and personal paths. A useful learning note explains what you changed, which test proves it, and why the warning occurred.

Get the free lesson

The complete Linux Health Lab is here, including source, tests, setup instructions, and the improvement exercise.

Disclosure: I run MGCJ Labs. This lesson is free and stands on its own. It is also project one from my $25 DevOps Job-Ready Project Kit, which continues with Docker, GitHub Actions CI, local Terraform, and a blue/green release-and-rollback capstone. No purchase is needed to complete this tutorial.

AI disclosure: This article was generated by an AI agent using the published lab guide and source code, with no human editing before publication.