Gaming industry under DDoS attack. Get DDoS protection now. Start onboarding
  1. Home
  2. Developers
  3. How to Monitor System Resources in Linux Using Command Line Tools

How to Monitor System Resources in Linux Using Command Line Tools

  • By Gcore
  • December 22, 2023
  • 3 min read
How to Monitor System Resources in Linux Using Command Line Tools

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.

What Makes Monitoring System Resources in Linux Essential

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.

Now that we’ve established the importance of this skill, let’s move to the next section where we will explore how to monitor system resources in Linux using command-line tool.

Process to Monitor System Resources in Linux with Command Line Tools

Monitoring system resources in Linux using command line tools involves several steps with various commands. Here’s a guide in sentence form for each tool:

#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.

top

#2 Using htop for Enhanced Monitoring

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.

#3 Using vmstat for Virtual Memory Stats

Execute ‘vmstat’ followed by a time interval to monitor virtual memory statistics, including swap usage and system operations. For example:

vmstat 5

#4 Using iostat for CPU and I/O Statistics

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.

iostat 5

#5 Using free to Check Memory Usage

Run the command free, and use -m or -g for outputs in MB or GB, respectively, to review your system’s memory usage.

free -h

#6 Using netstat for Network Statistics

Enter netstat to view network connections and routing tables, and add flags like -a or -t for more detailed information.

netstat -a

#7 Using df for Disk Space Usage

Type df in the terminal, and use the -h flag for a human-readable format, to examine disk space usage for each mounted filesystem.

df -h

#8 Using du for Directory Space Usage

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

#9 Using mpstat for Multi-Processor Usage

Run mpstat followed by a time interval (e.g., mpstat 5) to analyze CPU usage for each processor.

mpstat -P ALL 5

#10 Using nmon—Overall System Monitoring

Interactive monitor that displays CPU, memory, network, and disk usage. Press various keys to view different statistics.

nmon

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.

Conclusion

Looking to deploy Linux in the cloud? With Gcore Cloud, you can choose from Basic VM, Virtual Instances, or VPS/VDS suitable for Linux:

Choose an instance

Related articles

Multi-Cloud Plan: What It Is and How It Works

Your cloud provider goes down. Applications fail. Customers can't access your services. And because you've built everything around a single vendor, there's nothing you can do but wait. For organizations locked into one cloud platform, this

Vendor Lock-In in Cloud Computing: What It Is and How to Avoid It

Imagine discovering that migrating your company's data to a new cloud provider will cost hundreds of thousands of dollars in egress fees alone, before you've even touched the re-engineering work. Or worse, picture being in Synapse Financial

What Is Sovereign Cloud and Why Does It Matter?

Picture this: a foreign government issues a legal order forcing your cloud provider to hand over sensitive patient records, classified research data, or critical national infrastructure details. You can't stop it. This isn't hypothetical. G

Types of Virtualization in Cloud Computing

Your physical servers are sitting idle at 15% to 20% CPU utilization while you're paying for 100% of the power, cooling, and hardware costs. Meanwhile, your competitors have consolidated 10 to 15 applications per server, pushing utilization

What's the difference between multi-cloud and hybrid cloud?

Multi-cloud and hybrid cloud represent two distinct approaches to distributed computing architecture that build upon the foundation of cloud computing to help organizations improve their IT infrastructure.Multi-cloud environments involve us

What is multi-cloud? Strategy, benefits, and best practices

Multi-cloud is a cloud usage model where an organization utilizes public cloud services from two or more cloud service providers, often combining public, private, and hybrid clouds, as well as different service models, such as Infrastructur

Subscribe to our newsletter

Get the latest industry trends, exclusive insights, and Gcore updates delivered straight to your inbox.