How to Check CPU and Memory Usage in Debian 12 Bookworm

Learn how to check CPU and memory usage in Debian 12 Bookworm using built-in command-line tools and graphical utilities.

Monitoring system resources such as CPU and memory usage is essential for ensuring the smooth operation of a Debian 12 Bookworm system. Whether you are a system administrator, developer, or an everyday user, understanding how to check and analyze these resources can help you troubleshoot performance issues, optimize system performance, and prevent potential crashes.

In this article, we will explore various methods to check CPU and memory usage in Debian 12 Bookworm using built-in command-line tools and graphical utilities.

1. Checking CPU Usage

1.1 Using top Command

The top command is one of the most widely used tools for monitoring CPU and memory usage in real time. It provides an overview of system resource usage, including running processes, memory consumption, and CPU load.

To run the top command, open a terminal and enter:

 top

By default, top displays:

  • CPU usage as a percentage.
  • Memory and swap usage.
  • Running processes.
  • Load average (system load over time).

Press q to exit the top interface.

1.2 Using htop Command (Improved Version of top)

The htop command is an interactive system-monitoring tool that provides a more user-friendly interface than top. It includes color-coded output and allows for easier process management.

To install htop (if not already installed), run:

 sudo apt update && sudo apt install htop

Then, launch htop by typing:

 htop

1.3 Using mpstat Command

The mpstat command, part of the sysstat package, provides detailed CPU usage statistics.

First, install the sysstat package:

 sudo apt install sysstat

Then, run:

 mpstat

For a more detailed per-core CPU usage report, use:

 mpstat -P ALL

1.4 Using /proc/stat

The /proc/stat file contains CPU usage statistics. You can check it with:

 cat /proc/stat

This method provides raw CPU data, which can be analyzed further if needed.

2. Checking Memory Usage

2.1 Using free Command

The free command is a simple and effective way to check memory usage.

Run:

 free -h

The -h flag displays the output in human-readable format, showing:

  • Total memory.
  • Used memory.
  • Free memory.
  • Available memory.
  • Swap usage.

2.2 Using /proc/meminfo

Another way to check memory usage is by reading the /proc/meminfo file:

 cat /proc/meminfo

This file provides detailed information about memory usage, including cached and buffered memory.

2.3 Using vmstat Command

The vmstat command provides a detailed report of memory, CPU, and process statistics.

To install vmstat, use:

 sudo apt install procps

Then, run:

 vmstat 1 5

This command will display system performance metrics at one-second intervals, five times.

2.4 Using smem Command

The smem command provides a detailed breakdown of memory usage per process.

To install smem, run:

 sudo apt install smem

Then, execute:

 smem -t

3. Graphical Tools for Monitoring CPU and Memory Usage

If you prefer a graphical user interface (GUI) to monitor system resources, Debian 12 Bookworm offers several tools.

3.1 GNOME System Monitor

For users running the GNOME desktop environment, the built-in System Monitor is a great choice.

To launch it:

  1. Open the Applications menu.
  2. Search for “System Monitor.”
  3. Click to open it.

This tool provides an easy-to-read overview of CPU, memory, and disk usage.

3.2 KDE System Monitor

KDE users can use the built-in System Monitor, which provides similar functionality to the GNOME System Monitor.

To install it (if not already installed), run:

 sudo apt install plasma-systemmonitor

3.3 glances (Cross-Platform Monitoring Tool)

glances is a powerful system monitoring tool that provides real-time information about CPU, memory, disk, and network usage.

To install glances, run:

 sudo apt install glances

Then, start it with:

 glances

4. Automating Resource Monitoring

For long-term monitoring and logging, you can use tools like sar (part of sysstat) or set up a monitoring system such as Prometheus with Node Exporter.

4.1 Using sar

First, install sysstat if you haven’t already:

 sudo apt install sysstat

Enable and start the service:

 sudo systemctl enable sysstat
 sudo systemctl start sysstat

Then, view historical CPU usage with:

 sar -u 5 10

4.2 Using Prometheus with Node Exporter

For enterprise-level monitoring, Prometheus and Grafana provide powerful visualization and alerting capabilities. You can install Node Exporter to collect system metrics and send them to Prometheus.

Conclusion

Monitoring CPU and memory usage in Debian 12 Bookworm is crucial for maintaining optimal system performance. Whether you prefer command-line tools like top, htop, mpstat, and free, or graphical tools like GNOME System Monitor and glances, Debian offers a variety of options to suit your needs.

By using these tools, you can analyze resource usage, identify bottlenecks, and optimize your system for better performance. Additionally, automating monitoring with sar or Prometheus ensures continuous tracking of resource usage over time.

With this knowledge, you can efficiently manage your Debian 12 system and troubleshoot any performance-related issues that arise.