Using Bash to Monitor Server Health (CPU, RAM, Disk) – A Beginner-Friendly Guide

BackerLeader posted 3 min read
Keeping an eye on your server’s health doesn’t have to be complex — you don’t need flashy dashboards or paid tools to get started. With just a few lines of Bash, you can monitor key system metrics like CPU usage, memory consumption, and disk space right from your terminal.

In this post, we’ll walk you through simple Bash commands and scripts you can use to monitor your server's health and keep your apps running smoothly. Perfect for beginners managing their own VPS, homelab, or local dev environment.


Why use Bash?

Bash is available on almost every Linux server by default. It’s lightweight, scriptable, and requires no fancy setup. Whether you’re running a Laravel app on a VPS or just hosting a few projects, these tools can help you stay ahead of performance issues.


1. Check CPU Usage

To get a real-time snapshot of CPU activity:

top -n 1 | grep "Cpu(s)"

Output example:

%Cpu(s):  15.0 us,  5.0 sy,  0.0 ni, 75.0 id, 5.0 wa, 0.0 hi, 0.0 si, 0.0 st
  • us: user space usage (apps)
  • sy: system usage (kernel)
  • id: idle — higher is better
  • wa: waiting for I/O
Tip: If idle drops below 20% consistently, your server is working hard. Time to optimize or upgrade.

2. Check RAM (Memory) Usage

Run this command to see how much memory is being used:

free -h

Output example:

              total        used        free      shared  buff/cache   available
Mem:           2.0G        1.3G        100M        150M        600M        400M
  • used: actual memory used
  • buff/cache: memory being used for buffering and caching (not a problem)
  • available: what’s left for apps to use
What to watch for: If `available` memory is consistently low, your server may slow down or start swapping.

3. Check Disk Space

To check available storage:

df -h

Output example:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G   15G  4.5G  78% /
  • Use%: Keep this below 80% if possible.
  • If you hit 100%, your apps may crash or fail to write logs or temp files.
Pro Tip: Clear old logs and cached files with `sudo journalctl --vacuum-time=7d`

Bonus: Combine into a Simple Monitoring Script

Create a simple script to output all this in one go:

#!/bin/bash

echo "==== CPU Usage ===="
top -bn1 | grep "Cpu(s)"

echo ""
echo "==== Memory Usage ===="
free -h

echo ""
echo "==== Disk Space ===="
df -h

Save this as health-check.sh, then:

chmod +x health-check.sh
./health-check.sh

Make It Even Better: Email or Log the Results

You can schedule the script with cron and even send yourself the results via email or log to a file:

Cron example: Run every hour

0 * * * * /path/to/health-check.sh >> /var/log/health-monitor.log

Why This Matters (Especially for Developers)

Server health monitoring helps you **avoid downtime**, catch issues before they escalate, and understand how your app behaves in production — especially when you're running Laravel, Dockerized services, or a VPS.

Whether you're hosting a homelab, learning DevOps, or managing a production app, Bash can give you visibility without overhead.


Final Thoughts

Monitoring doesn’t need to be complicated. Bash provides a simple, fast, and effective way to stay in control. As your needs grow, you can always integrate tools like Netdata, Prometheus, or Grafana, but it all starts here — in the terminal.

Want more Bash tricks or VPS insights? Stick around — CoderLegion is where developers level up with real-world code and simple guides.

If you read this far, tweet to the author to show them you care. Tweet a Thanks

Good Post! Thanks To Share

More Posts

Setup a LAMP Server on a VPS in Under an Hour: The Ultimate Guide to Web Hosting

Gift Balogun - Feb 19

A Shell script that sends a file using magic-wormhole cli

Vaishnav-sabari-girish - Sep 30

How to Create a Custom Artisan Command in Laravel

Darlington Okorie - May 11

Automating MySQL Backups on a VPS with Telegram Alerts Part 2

Gift Balogun - Mar 22

Automate Your VPS Database Backups Like a Pro: A Complete MySQL Backup Script

Gift Balogun - Mar 15
chevron_left