
{{ $('Map tags to IDs').item.json.title }}
How to Check CPU and Memory Usage
Monitoring CPU and memory usage is essential for managing system performance and ensuring applications run smoothly. Linux provides various command-line tools to check CPU and memory usage effectively. This tutorial will guide you through some of these tools and their usage.
1. Using the top Command
The top
command provides a dynamic view of system processes, including CPU and memory usage. To start top
, run:
top
In the top output, you’ll see a summary of the CPU and memory usage at the top:
- %CPU: Percentage of CPU usage by all processes.
- %MEM: Percentage of memory used.
To quit top
, press q
.
2. Using the htop Command
htop
is an improved version of top
with a more user-friendly interface. If it’s not installed, install it using:
- For Ubuntu:
sudo apt install htop
- For CentOS:
sudo yum install htop
Run htop
with the following command:
htop
It presents a colorful display of CPU and memory usage, alongside the list of processes. You can navigate through processes and kill them directly from the interface.
3. Using the free Command
The free
command displays memory usage details, including total, used, and available memory:
free -h
The -h
option provides output in a human-readable format. Here’s what the output represents:
- Total: Total memory available.
- Used: Memory in use by processes.
- Free: Memory not in use.
- Available: Memory available for new processes without swapping.
4. Using the vmstat Command
The vmstat
command reports information about processes, memory, paging, block IO, traps, and CPU activity:
vmstat 1
This will provide updates every second. Look for the us (user time) and sy (system time) columns to gauge CPU activity.
5. Using the mpstat Command
The mpstat
command displays CPU usage for all available CPUs:
mpstat -P ALL 1
This command shows CPU activity for each core every second.
6. Conclusion
By following this tutorial, you now know how to effectively monitor CPU and memory usage in Linux using various commands such as top
, htop
, free
, vmstat
, and mpstat
. Regularly monitoring resource usage helps maintain optimal system performance and troubleshoot potential issues. Continue exploring additional monitoring tools to further enhance your Linux administration skills!