How to Use Linux Performance Monitoring Commands

Introduction

In Linux systems, system monitoring and performance analysis are an indispensable part of the daily work of system administrators and developers. By monitoring linux performance, we can promptly identify and resolve potential issues, ensuring system stability and efficiency. This article will introduce 5 powerful Linux performance monitoring commands and showcase their capabilities through detailed usage examples.

1. Linux Performance Monitoring Commands – top

1.1 Overview

The top command is one of the most commonly used real-time linux performance monitoring commands. It dynamically displays the activity of system processes, including the usage of CPU, memory, swap partition, and other resources.

1.2 Usage Examples

1.2.1 Basic Usage

By entering the top command in the terminal, the system will display the current real-time status:

The output will be as follows:

1.2.2 Sorting by CPU Usage

In the top interface, pressing the P key will sort the processes by CPU usage:

1.2.3 Sorting by Memory Usage

In the top interface, pressing the M key will sort processes by memory usage:

1.3 Summary

The top command is a very powerful real-time monitoring tool that helps us quickly understand the system’s operational state and resource usage. By sorting by CPU or memory usage, we can quickly identify processes that consume significant resources.

2. Linux Performance Monitoring Commands –vmstat

2.1 Overview

The vmstat command is used to report virtual memory statistics, including processes, memory, paging, block IO, traps, and CPU activity. It helps us understand the overall performance status of the system.

2.2 Usage Examples

2.2.1 Basic Usage

By entering the vmstat command in the terminal, the system will display the current virtual memory statistics:

The output will be as follows:

2.2.2 Periodic Refresh

We can use the periodic refresh feature of the vmstat command to refresh statistics at regular intervals. For example, refreshing every 2 seconds:

The output will be as follows:

2.2.3 Displaying a Specified Number of Statistics

We can use the vmstat command to display statistics a specified number of times. For example, displaying statistics 5 times:

The output will be as follows:

2.3 Summary

The vmstat command helps us comprehensively understand the usage of virtual memory, processes, CPU, and other resources. By periodically refreshing and displaying a specified number of statistics, we can better monitor system performance.

3. Linux Performance Monitoring Commands –iostat

3.1 Overview

The iostat command is used to monitor the load of input/output devices in the system, including CPU utilization, device utilization, throughput, and other information. It helps us analyze disk IO performance issues.

3.2 Usage Examples

3.2.1 Basic Usage

By entering the iostat command in the terminal, the system will display the current IO statistics:

The output will be as follows:

3.2.2 Periodic Refresh

We can use the periodic refresh feature of the iostat command to refresh statistics at regular intervals. For example, refreshing every 2 seconds:

The output will be as follows:

3.2.3 Displaying a Specified Number of Statistics

We can use the iostat command to display statistics a specified number of times. For example, displaying statistics 5 times:

The output will be as follows:

3.3 Summary

The iostat command helps us monitor the IO device load and analyze disk IO performance issues. By periodically refreshing and displaying a specified number of statistics, we can better understand the system’s IO performance.

4. Linux Performance Monitoring Commands –netstat

4.1 Overview

The netstat command is used to display information about network connections, routing tables, interface statistics, masquerade connections, multicast memberships, and more. It helps us monitor network connections and diagnose network issues.

4.2 Usage Examples

4.2.1 Displaying All Connections

By entering the netstat command in the terminal, the system will display all network connections:

The output will be as follows:

4.2.2 Displaying Listening Ports

We can use the netstat command to display all listening ports:

The output will be as follows:

4.2.3 Displaying the Routing Table

We can use the netstat command to display the system’s routing table:

The output will be as follows:

4.3 Summary

The netstat command helps us monitor network connections, routing tables, interface statistics, etc., making it a powerful tool for diagnosing network problems. By displaying all connections, listening ports, and the routing table, we can gain a comprehensive understanding of the system’s network status.

5. Linux Performance Monitoring Commands –sar

5.1 Overview

The sar command is a system activity report tool used to collect, report, and save system activity information. It can monitor the usage of CPU, memory, disk IO, network, and other resources, generating detailed reports.

5.2 Usage Examples

5.2.1 Basic Usage

By entering the sar command in the terminal, the system will display the current system activity information:

The output will be as follows:

5.2.2 Displaying CPU Usage

We can use the sar command to display CPU usage:

The output will be as follows:

5.2.3 Displaying Memory Usage

We can use the sar command to display memory usage:

The output will be as follows:

5.2.4 Displaying Disk IO Usage

We can use the sar command to display disk IO usage:

The output will be as follows:

5.3 Summary

The sar command is a very powerful system activity report tool that helps us comprehensively monitor system resources such as CPU, memory, and disk IO. By generating detailed reports, we can better analyze performance issues in the system.

Conclusion

In Linux systems, system monitoring and performance analysis are important means to ensure system stability and efficiency. This article introduced 5 powerful linux performance monitoring commands: top, vmstat, iostat, netstat, and sar, and demonstrated their functionality through detailed usage examples. With these commands, we can gain a comprehensive understanding of the system’s operational state and promptly identify and resolve potential performance issues. We hope this article helps readers better master the skills of Linux system monitoring and performance analysis.