DEV Community

Cover image for Ubuntu Server Resource Monitoring via Command Line
Md Abu Musa
Md Abu Musa

Posted on

Ubuntu Server Resource Monitoring via Command Line

Monitoring system resources is a critical responsibility for backend engineers, DevOps engineers, and system administrators. Whether you are running a Laravel API, Node.js app, Docker containers, or an AWS EC2 instance, understanding how your Ubuntu server consumes CPU, memory, disk, and network resources helps you:

  • Detect performance bottlenecks early
  • Prevent unexpected downtime
  • Optimize application performance
  • Make informed scaling decisions

This blog provides a professional, practical, and production-oriented guide to checking system resource usage on an Ubuntu Server using only command-line tools.

1. Why Resource Monitoring Matters

In real-world production environments, issues like:

  • Slow API responses
  • Sudden 504 Gateway Timeout errors
  • Random application crashes
  • Server freeze or reboot

are often symptoms of resource exhaustion rather than application bugs.

Regular monitoring helps answer critical questions:

  • Is CPU overloaded?
  • Is RAM exhausted or swapping?
  • Is disk space full?
  • Is disk I/O causing delays?
  • Which process is consuming the most resources?

2. Quick System Health Overview

Command

uptime
Enter fullscreen mode Exit fullscreen mode

What it shows

  • System running time
  • Number of logged-in users
  • Load average (1, 5, 15 minutes)

How to interpret load average

If your server has 4 CPU cores:

  • Load average ≈ 4 → normal
  • Load average > 4 → CPU under pressure
  • Load average >> 4 → serious performance issue

This is the fastest health check command you should use first.

3. Real-Time CPU and Memory Monitoring

Using top

top
Enter fullscreen mode Exit fullscreen mode

Key metrics

  • %CPU → CPU usage per process
  • %MEM → Memory usage per process
  • load average → overall CPU load

Useful shortcuts

  • Shift + P → sort by CPU usage
  • Shift + M → sort by memory usage
  • q → quit

top is available by default on all Ubuntu servers.

Using htop (Recommended)

sudo apt install htop
htop
Enter fullscreen mode Exit fullscreen mode

Why htop is better

  • Color-coded CPU and memory bars
  • Easy process killing
  • Tree view of processes
  • Mouse support

For daily production monitoring, htop is strongly recommended.

4. Memory (RAM) Usage Analysis

Command

free -h
Enter fullscreen mode Exit fullscreen mode

Key fields explained

  • total → Total RAM
  • used → Used memory
  • available → Memory available for new processes

⚠️ Important: Always focus on available, not free. Linux uses free memory for caching, which is normal and healthy.

If available memory is very low, your server may start swapping or killing processes.

5. Disk Usage Monitoring

Overall disk usage

df -h
Enter fullscreen mode Exit fullscreen mode

Shows:

  • Total disk size
  • Used space
  • Available space
  • Mount points

⚠️ If disk usage reaches 90%+, services like MySQL, Redis, or Docker may fail.

Directory-wise disk usage

du -sh /path/to/directory
Enter fullscreen mode Exit fullscreen mode

Example:

du -sh /var/www
du -sh /var/log
Enter fullscreen mode Exit fullscreen mode

This helps identify which folders are consuming disk space.

6. CPU Information and Core Count

Command

lscpu
Enter fullscreen mode Exit fullscreen mode

Provides:

  • CPU architecture
  • Number of cores
  • Threads per core
  • CPU model

Knowing the core count is essential for correctly interpreting load average.

7. Network Usage Monitoring

Basic network statistics

ip -s link
Enter fullscreen mode Exit fullscreen mode

Shows transmitted and received packets per network interface.

Real-time network monitoring

sudo apt install nload
nload
Enter fullscreen mode Exit fullscreen mode

Useful when:

  • APIs feel slow
  • Upload/download speed is suspicious
  • External service calls timeout

8. Disk I/O Performance (Often Overlooked)

High disk I/O wait can slow down applications even when CPU and RAM look normal.

Command

sudo apt install sysstat
iostat
Enter fullscreen mode Exit fullscreen mode

Look for:

  • High %iowait
  • Slow read/write rates

This is critical for database-heavy applications.

9. Identify Resource-Hungry Processes

Top memory-consuming processes

ps aux --sort=-%mem | head
Enter fullscreen mode Exit fullscreen mode

Top CPU-consuming processes

ps aux --sort=-%cpu | head
Enter fullscreen mode Exit fullscreen mode

This is extremely useful during production incidents.

10. One-Command Live Summary

Command

vmstat 1
Enter fullscreen mode Exit fullscreen mode

Updates every second and shows:

  • CPU usage
  • Memory usage
  • Swap activity
  • Disk I/O

A powerful command for advanced troubleshooting.

11. Recommended Monitoring Workflow (Production)

  1. uptime → Quick health check
  2. htop → Live CPU & memory monitoring
  3. free -h → Memory availability
  4. df -h → Disk usage
  5. iostat → Disk I/O issues
  6. ps aux → Identify problematic processes

12. Conclusion

Command-line monitoring tools are lightweight, fast, and reliable, making them perfect for Ubuntu servers in production.

By mastering these commands, you can:

  • Debug performance issues confidently
  • Reduce downtime
  • Communicate system health clearly to your team
  • Grow from a backend engineer into a strong DevOps-aware professional

Regular monitoring is not optional — it is a core engineering habit.

Top comments (0)