Learn how to monitor your Linux system’s performance using command line tools with our easy-to-understand guide. Whether you’re a system administrator or a curious user, this guide introduces you to the essential command line utilities that give you real-time insights into your system’s CPU usage, memory allocation, and more. You’ll learn how to track and manage your Linux system’s resources precisely and efficiently. Follow along and discover the power of command line tools for monitoring system resources in Linux.
Knowing how to monitor system resources in Linux is crucial for several reasons, particularly for system administrators, developers, and power users. Here are five key reasons why this skill is important:
- Performance Optimization. By monitoring system resources, you can identify processes or applications that are consuming excessive resources, such as CPU, memory, or disk I/O. This allows you to make adjustments to optimize the performance of your system or applications.
- Troubleshooting Issues. Understanding resource usage helps in diagnosing and resolving system issues. For instance, if a server is responding slowly, monitoring tools can help determine if it’s due to high CPU load, insufficient memory, or other resource constraints.
- Capacity Planning. Regular monitoring provides data over time, which can be crucial for capacity planning. You can predict when you’ll need to upgrade hardware or scale your system based on trends in resource usage.
- Security Monitoring. Monitoring tools can also help in identifying unusual activities that might indicate a security breach, such as unexpected spikes in network traffic or unusual processes consuming resources.
Process to Monitor System Resources in Linux with Command Line Tools
#1 Using top for Real-Time Monitoring
Open a terminal and enter the command below to view real-time system resource usage, including CPU, memory, and process information.
To use the htop command, first install it using the command below:
sudo apt-get install htop
Then run it by typing “htop” in your terminal to see a user-friendly display of processes.
Execute ‘vmstat’ followed by a time interval to monitor virtual memory statistics, including swap usage and system operations. For example:
Install the sysstat package with sudo apt-get install sysstat, use iostat along with an optional time interval to observe CPU statistics and I/O transfer rates.
Run the command free, and use -m or -g for outputs in MB or GB, respectively, to review your system’s memory usage.
Enter netstat to view network connections and routing tables, and add flags like -a or -t for more detailed information.
Type df in the terminal, and use the -h flag for a human-readable format, to examine disk space usage for each mounted filesystem.
Use du followed by a directory path, and add -h for human-readable output, to assess the space used by that directory and its sub-directories.
du -sh /path/to/directory
Run mpstat followed by a time interval (e.g., mpstat 5) to analyze CPU usage for each processor.
mpstat -P ALL 5
Interactive monitor that displays CPU, memory, network, and disk usage. Press various keys to view different statistics.
That’s it! Now, you’re equipped to monitor your system resources. Each tool offers unique insights into your Linux system’s performance and health. Regular monitoring with these tools can assist in proactive system management and troubleshooting.
Looking to deploy Linux in the cloud? With Gcore Cloud, you can choose from Basic VM, Virtual Instances, or VPS/VDS suitable for Linux:
- Gcore Basic VM offers shared virtual machines from €3.2 per month
- Virtual Instances are virtual machines with a variety of configurations and an application marketplace
- Virtual Dedicated Servers provide outstanding speed of 200+ Mbps in 20+ global locations