{"id":5313,"date":"2026-01-27T18:55:31","date_gmt":"2026-01-27T13:25:31","guid":{"rendered":"https:\/\/w3buddy.com\/?p=5313"},"modified":"2026-01-31T12:26:24","modified_gmt":"2026-01-31T06:56:24","slug":"how-to-monitor-system-load-average-periodically-in-linux","status":"publish","type":"post","link":"https:\/\/w3buddy.com\/blog\/how-to-monitor-system-load-average-periodically-in-linux\/","title":{"rendered":"How to Monitor System Load Average Periodically in Linux"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Monitoring system performance is a critical task for system administrators and developers. While the <code>top<\/code> command provides comprehensive resource information, sometimes you need a lighter, more focused approach to track specific metrics over time. This guide demonstrates how to create a simple monitoring loop to periodically check CPU load average and memory usage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding the Need<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When troubleshooting performance issues or monitoring system behavior during specific operations, you may want to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Track CPU load trends without the overhead of full system monitoring tools<\/li>\n\n\n\n<li>Record memory and swap usage at regular intervals<\/li>\n\n\n\n<li>Create a lightweight monitoring solution that can run in the background<\/li>\n\n\n\n<li>Capture snapshots of system state for later analysis<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">The Solution: Using a While Loop<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of continuously watching <code>top<\/code>, we can create a simple loop that checks specific metrics at defined intervals. This approach uses the <code>while true<\/code> construct combined with standard Linux commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Syntax<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>while true; do\n    date\n    cat \/proc\/loadavg\n    free\n    sleep 600\ndone<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Breaking Down the Command<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>while true<\/code><\/strong>: Creates an infinite loop that continues until manually stopped<\/li>\n\n\n\n<li><strong><code>date<\/code><\/strong>: Displays the current timestamp for each check<\/li>\n\n\n\n<li><strong><code>cat \/proc\/loadavg<\/code><\/strong>: Shows the 1-minute, 5-minute, and 15-minute load averages<\/li>\n\n\n\n<li><strong><code>free<\/code><\/strong>: Displays memory and swap usage statistics<\/li>\n\n\n\n<li><strong><code>sleep 600<\/code><\/strong>: Pauses for 600 seconds (10 minutes) between checks<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Example Output<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what the monitoring output looks like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&#91;user@server ~]$ while true; do\n    date\n    cat \/proc\/loadavg\n    free\n    sleep 600\ndone<\/strong>\n\nMon Jan 25 18:52:26 CST 2026\n16.80 9.99 4.23 17\/760 473640\n               total        used        free      shared  buff\/cache   available\nMem:        49065224    32839616      763044    13857116    29796508    16225608\nSwap:       24731644     1896372    22835272\n\nMon Jan 25 19:02:26 CST 2026\n17.12 16.02 10.29 7\/759 473766\n               total        used        free      shared  buff\/cache   available\nMem:        49065224    33099712      787048    13891812    29546760    15965512\nSwap:       24731644     1809076    22922568\n\nMon Jan 25 19:12:26 CST 2026\n17.28 17.16 13.63 4\/760 473838\n               total        used        free      shared  buff\/cache   available\nMem:        49065224    33306620      845572    13908896    29298320    15758604\nSwap:       24731644     1720500    23011144\n...<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Interpreting the Results<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Load Average Values<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The three numbers in <code>\/proc\/loadavg<\/code> represent:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>First number<\/strong>: 1-minute load average<\/li>\n\n\n\n<li><strong>Second number<\/strong>: 5-minute load average<\/li>\n\n\n\n<li><strong>Third number<\/strong>: 15-minute load average<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A load average higher than your number of CPU cores typically indicates the system is under stress.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Memory Information<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>free<\/code> command shows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Total<\/strong>: Total installed memory<\/li>\n\n\n\n<li><strong>Used<\/strong>: Memory currently in use<\/li>\n\n\n\n<li><strong>Free<\/strong>: Completely unused memory<\/li>\n\n\n\n<li><strong>Buff\/cache<\/strong>: Memory used for buffers and cache<\/li>\n\n\n\n<li><strong>Available<\/strong>: Memory available for new applications (more accurate than &#8220;free&#8221;)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Stopping the Monitor<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To stop the monitoring loop, simply press <strong>Ctrl + C<\/strong> in the terminal. This sends an interrupt signal that terminates the loop.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Customization Options<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Adjust the Monitoring Interval<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Change the <code>sleep<\/code> value to modify how frequently checks occur:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sleep 300   <em># Check every 5 minutes<\/em>\nsleep 60    <em># Check every minute<\/em>\nsleep 3600  <em># Check every hour<\/em><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Add Additional Metrics<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can expand the monitoring to include other system information:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while true; do\n    date\n    echo \"=== Load Average ===\"\n    cat \/proc\/loadavg\n    echo \"=== Memory Usage ===\"\n    free -h\n    echo \"=== Disk Usage ===\"\n    df -h\n    echo \"=== Top Processes ===\"\n    ps aux --sort=-%cpu | head -6\n    sleep 600\ndone<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Save Output to a File<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Redirect the output to a file for later analysis:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while true; do\n    date\n    cat \/proc\/loadavg\n    free\n    sleep 600\ndone &gt;&gt; system_monitor.log 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Using in Shell Scripts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This technique is particularly useful when incorporated into shell scripts for automated monitoring:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n<em># system_monitor.sh - Simple system monitoring script<\/em>\n\nLOG_FILE=\"\/var\/log\/custom_monitor.log\"\nINTERVAL=600  <em># 10 minutes<\/em>\n\nwhile true; do\n    {\n        echo \"====================\"\n        date\n        echo \"Load Average:\"\n        cat \/proc\/loadavg\n        echo \"Memory Status:\"\n        free -h\n        echo \"\"\n    } &gt;&gt; \"$LOG_FILE\"\n    \n    sleep \"$INTERVAL\"\ndone<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Make the script executable and run it in the background:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod +x system_monitor.sh\nnohup .\/system_monitor.sh &amp;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Choose appropriate intervals<\/strong>: Very frequent checks can consume resources; balance monitoring needs with system overhead<\/li>\n\n\n\n<li><strong>Log rotation<\/strong>: If saving to files, implement log rotation to prevent disk space issues<\/li>\n\n\n\n<li><strong>Use meaningful timestamps<\/strong>: Include date and time for easier troubleshooting<\/li>\n\n\n\n<li><strong>Monitor during specific events<\/strong>: Run the loop during database migrations, application deployments, or load testing<\/li>\n\n\n\n<li><strong>Combine with alerts<\/strong>: Parse the output to trigger notifications when thresholds are exceeded<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This simple monitoring approach provides a lightweight alternative to full-featured monitoring tools when you need focused, periodic system checks. The flexibility of the while loop allows you to customize exactly what you monitor and how often, making it an invaluable tool in any system administrator&#8217;s toolkit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Whether you&#8217;re troubleshooting performance issues, establishing baseline metrics, or monitoring system behavior during specific operations, this technique offers a quick and effective solution without the complexity of enterprise monitoring systems.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Monitoring system performance is a critical task for system administrators and developers. While the top command provides comprehensive resource information, sometimes you need a lighter, more focused approach to track specific metrics over time. This guide demonstrates how to create a simple monitoring loop to periodically check CPU load average and memory usage. Understanding the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5314,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAowu461DA:productID":"","footnotes":""},"categories":[1225],"tags":[],"class_list":["post-5313","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/5313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/comments?post=5313"}],"version-history":[{"count":1,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/5313\/revisions"}],"predecessor-version":[{"id":5315,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/5313\/revisions\/5315"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media\/5314"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=5313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=5313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/tags?post=5313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}