• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

Roger Perkin

Network Automation Architect

  • Network Automation
    • Network Automation Courses
    • What is NetDevOps?
    • Workflow Orchestration
    • Ansible Automation Platform
    • Ansible Workshop
    • What is Network Automation?
    • Network Automation Tools
    • ContainerLab
    • Ansible Training
      • What is Ansible?
      • Ansible Tutorial for Beginners
      • Ansible Network Automation
      • Ansible Hosts File
    • Python Network Automation
      • Nornir
      • Python Network Automation Course
      • Python for Network Engineers
      • Python VENV / Virtual Environment Tutorial
      • Python Tutorial for Beginners
      • pyATS
    • Network Source of Truth
      • NetBox Training
      • Infrahub
    • NetDevops
    • DevOps Tutorial
      • Git Training
      • Terraform Training
      • Linux Training
      • Kubernetes Training
      • Devops Training Course
      • Azure Devops Training
    • Terraform
    • GIT
      • Git Commands
      • What is GitHub?
    • Docker Training
    • Confluence
    • Microsoft Azure
  • Cisco
    • ISE
    • SD WAN Training
    • Password Recovery
    • Software-Upgrade-Guides
    • BGP
    • Data Center
    • WIRELESS
  • CCIE
  • Blog
  • About
    • My Red Special Guitar
  • Contact

How to monitor Ubuntu Server for Disk and CPU usage

Home » Linux


Monitoring CPU Usage

1. Top Command

The top command provides a real-time view of system resource usage, including CPU usage.

top
  • Press 1 within top to view the usage per CPU core (if you have multiple cores).

2. htop (Interactive Version of top)

htop is a more user-friendly, colorized version of top. You may need to install it first:

sudo apt update
sudo apt install htop

Once installed, you can run:

htop
  • You can use F6 to sort by CPU, memory, or other metrics.

3. mpstat (CPU Usage by Core)

To monitor the CPU usage on a per-core basis, you can use mpstat from the sysstat package.
First, install sysstat if you haven’t already:

sudo apt update
sudo apt install sysstat

Then, you can check CPU statistics:

mpstat -P ALL 1
  • This command shows CPU usage for all cores every 1 second.

4. sar (Historical CPU Data)

sar can also give you historical CPU data if sysstat is installed.
To see CPU usage history:

sar -u 1 3
  • This will show CPU utilization every second for 3 times.

5. Using pidstat

If you need to monitor CPU usage by process:

pidstat -u 1

This will show the CPU usage by process every 1 second.


Monitoring Disk Usage

1. df – Disk Usage

The df command reports the amount of disk space used and available on the file system:

df -h
  • The -h flag makes the output human-readable (e.g., GB, MB).

2. du – Disk Usage of Specific Directory

The du command shows disk usage for files and directories. To view disk usage of a directory (and its subdirectories):

du -sh /path/to/directory
  • The -s flag provides a summary for the specified directory.
  • The -h flag makes the output human-readable.

3. iostat (Disk I/O Statistics)

The iostat command shows CPU and disk I/O statistics. You need the sysstat package installed for this.

sudo apt install sysstat

Then, run:

iostat -xz 1
  • This command provides detailed I/O statistics for each device, updating every 1 second.

4. smartctl (SMART Disk Health)

The smartctl command can give you detailed health information about your disks using SMART (Self-Monitoring, Analysis, and Reporting Technology).
First, install smartmontools:

sudo apt install smartmontools

Then, run:

sudo smartctl -a /dev/sda
  • Replace /dev/sda with your actual disk identifier.

5. dstat (Real-time System Resource Monitoring)

dstat is a versatile tool that shows various system resources in real-time, including disk and CPU usage.
Install it with:

sudo apt install dstat

Run it with:

dstat -cd
  • This will show both CPU and disk usage in real-time.

Other Useful Disk & CPU Monitoring Tools

1. Monitoring Disk Performance with vmstat

You can use vmstat to check system performance, including CPU and disk stats.

vmstat 1
  • This will update every second, giving you an overview of CPU, memory, and I/O activity.

2. Monitoring Disk Usage with lsblk

The lsblk command provides information about block devices and their mount points:

lsblk
  • This will show a tree of all your disks, partitions, and their mount points.

Example: Monitoring CPU & Disk Together

You can also monitor both CPU and disk in real time using dstat:

dstat -cd --disk-usage

This will show both CPU usage and disk usage in a real-time stream.


These are some of the basic and commonly used commands to monitor CPU and disk usage on an Ubuntu 22.04 server. You can use them individually or combine them depending on what you need to check (real-time vs. historical data).

Category: Linux
ansible course for network engineers
Get Access to my Ansible Course NOW
Previous Post:Juniper Cheat Sheet
Next Post:JNCIA DevOps

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Sidebar

Hi I'm Roger Perkin,
Based in the UK working as a Network Automation Architect, CCIE #50038
About Roger | Twitter | Linkedin

python course for network engineers

Topics

Network Automation
Ansible
Python for Network Automation
CCIE
Cisco ISE
F5 Certification
BGP
OSPF
Network Automation Conferences
auvik promo banner
Pluralsight Trial

Git for Network Engineers

Ansible vs Nornir

Start learning today with my Network Automation Courses

Master Ansible, Python, Git, Nornir, Jenkins and more..


Buy me a coffeeBuy me a coffee

ansible network automation course

Have you seen my YouTube Channel?

YouTube Subscribe

Let’s get started

Take a look at my premium courses on Ansible, Nornir & Git or buy them all with the Network Automation Bundle!

Network Automation Courses

Navigation

Python VENV Tutorial
Python for Network Engineers

Network Automation
Network Automation Courses
Network Discovery Tools
Network Automation Conferences
Ansible Training
What is Ansible?
Devops Tutorial
Network Source of Truth
DevOps Glossary
Network Monitoring Software

Contact

Contact

Get in touch with me here

[email protected]

  • Twitter
  • LinkedIn
  • YouTube
Buy me a coffeeBuy me a coffee

Copyright © 2025 · Roger Perkin · All Rights Reserved · Privacy Policy – Terms