<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Christopher Jones</title>
    <description>The latest articles on DEV Community by Christopher Jones (@christopher_jones_3426773).</description>
    <link>https://dev.to/christopher_jones_3426773</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4248206%2Fe2ff546e-3b29-4b85-bb89-b06fab7dbb02.jpg</url>
      <title>DEV Community: Christopher Jones</title>
      <link>https://dev.to/christopher_jones_3426773</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/christopher_jones_3426773"/>
    <language>en</language>
    <item>
      <title>Test a Linux health warning without filling your disk</title>
      <dc:creator>Christopher Jones</dc:creator>
      <pubDate>Mon, 16 Nov 2026 17:49:36 +0000</pubDate>
      <link>https://dev.to/christopher_jones_3426773/test-a-linux-health-warning-without-filling-your-disk-57mk</link>
      <guid>https://dev.to/christopher_jones_3426773/test-a-linux-health-warning-without-filling-your-disk-57mk</guid>
      <description>&lt;p&gt;A health monitor that only ever prints &lt;code&gt;OK&lt;/code&gt; is hard to trust. Before relying on it, you need to see its warning path and understand what another program receives when that happens.&lt;/p&gt;

&lt;p&gt;You can test that path without filling your disk: lower the warning threshold for one run.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Get the runnable sample
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://mgcjlabs.com/free-linux-health-lab?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=linux_health_lab" rel="noopener noreferrer"&gt;Download the free lesson and source code&lt;/a&gt;. No email signup or payment is required. The ZIP includes the monitor, six unit tests, and an offline guide.&lt;/p&gt;

&lt;p&gt;Open an Ubuntu terminal. On Windows, use the Ubuntu terminal in WSL2 for the commands below. Check your Python version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After extracting the ZIP, change into its &lt;code&gt;mgcj-free-linux-health-lab&lt;/code&gt; folder. The &lt;a href="https://mgcjlabs.com/free-lab/START_HERE.html" rel="noopener noreferrer"&gt;complete setup guide&lt;/a&gt; includes download, extraction, checksum verification, and Windows-to-WSL path examples.&lt;/p&gt;

&lt;p&gt;All subsequent commands run from that extracted folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Read the normal report
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;lab_exit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0
python3 project-01-linux-health/health_check.py &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nv"&gt;lab_exit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Monitor exit code: %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$lab_exit"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;available&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using available memory matters: memory Linux can reclaim is useful capacity, even when it is not completely unused.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;--disk-path /mnt/c&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Trigger a warning safely
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;lab_exit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0
python3 project-01-linux-health/health_check.py --disk-warning 0 &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nv"&gt;lab_exit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Monitor exit code: %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$lab_exit"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;This works because the comparison in the monitor is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;disk_percent&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;disk_warning&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;warnings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'disk'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Read JSON and exit status together
&lt;/h2&gt;

&lt;p&gt;The monitor uses these exit codes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Code&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Metrics read successfully; no warnings&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Metrics read successfully; a threshold was reached&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;A metric could not be read or validated&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;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 &lt;code&gt;status&lt;/code&gt; and &lt;code&gt;warnings&lt;/code&gt; fields. Argument errors produce usage/error text instead.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  5. Test the boundary, not just the obvious failure
&lt;/h2&gt;

&lt;p&gt;Run the included tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 -m unittest discover -s project-01-linux-health -p &lt;span class="s1"&gt;'test_*.py'&lt;/span&gt; -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

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

&lt;p&gt;Changing &lt;code&gt;&amp;gt;=&lt;/code&gt; to &lt;code&gt;&amp;gt;&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Make one tested improvement
&lt;/h2&gt;

&lt;p&gt;Try adding a &lt;code&gt;--status-only&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get the free lesson
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://mgcjlabs.com/free-linux-health-lab?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=linux_health_lab" rel="noopener noreferrer"&gt;The complete Linux Health Lab is here&lt;/a&gt;, including source, tests, setup instructions, and the improvement exercise.&lt;/p&gt;

&lt;p&gt;Disclosure: I run MGCJ Labs. This lesson is free and stands on its own. It is also project one from my &lt;a href="https://mgcjlabs.com/devops-job-ready-kit?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=linux_health_lab" rel="noopener noreferrer"&gt;$25 DevOps Job-Ready Project Kit&lt;/a&gt;, 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.&lt;/p&gt;

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

</description>
      <category>linux</category>
      <category>python</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
