In order to diagnose problems with Linux systems’ performance, one must look for difficulties with the CPU, RAM, disc I/O, network usage, and general responsiveness of the system. You can use the following popular Linux commands and utilities to troubleshoot performance issues:
1. top
and htop
Shows dynamic, real-time data on processes that are now active. It’s frequently used to keep an eye on the general performance of the system and pinpoint the processes that are using a lot of resources.
Command:
top
htop
2. vmstat
The Linux command-line programme vmstat, which stands for “virtual memory statistics,” gives information on memory, paging, processes, I/O, CPU, and disc scheduling, among other elements of the system 12. It is a component of the sysstat package, along with iostat and sar and other tools for system monitoring.
Command:
vmstat 1
3. iostat
Linux users can obtain CPU and input/output statistics for devices and partitions using the iostat command-line utility. Its purpose is to track the loading of system input/output devices by measuring the duration of each device’s operation in comparison to its typical transfer rate.
Here are some common uses of iostat
with examples:
- Basic usage: RunningĀ
iostat
Ā without any arguments will display CPU and device statistics since the last reboot. - Detailed statistics: Using theĀ
-x
Ā option will show more detailed statistics information.
iostat -x
- CPU statistics only: To display only CPU statistics, use theĀ
-c
Ā option.
iostat -c
- Device statistics only: TheĀ
-d
Ā option will display only the device report.
iostat -d
- Extended I/O statistics for devices: TheĀ
-xd
Ā option shows extended I/O statistics for devices only.
iostat -xd
- Statistics in kilobytes or megabytes: TheĀ
-k
Ā option captures the statistics in kilobytes, andĀ-m
Ā captures them in megabytes.
iostat -k
iostat -m
- Repetition and delay: You can set a count (the number of times to update) and a delay (the interval between updates). For instance, running iostat -k 2 3 will produce 3 reports and show CPU and device data with a 2-second lag between each report.
iostat -k 2 3
- Persistent device name statistics: TheĀ
-j
Ā option allows you to display persistent device name statistics.
iostat -j ID mmcbkl0 sda6 -x -m 2 2
- Statistics for block devices: TheĀ
-p
Ā option displays statistics for block devices.
iostat -p
- LVM2 statistic information: TheĀ
-N
Ā option displays LVM2 statistic information.
iostat -N
4. sar
(System Activity Reporter):
In Unix-like operating systems, the command-line utility sar, or System Activity Reporter, gathers, reports, and saves system activity data. It is used to track system performance data and is a component of the sysstat package. Real-time data on CPU load, memory paging, swap utilisation, network I/O, and other topics are available from Sar. Additionally, it can show historical data for particular time periods, enabling examination of previous performance problems.
After installation, sar allows you to view historical data from log files or real-time statistics. For instance, you only need to run sar into the terminal to see the CPU load for the current day. The command sar interval iterations, where interval is the number of seconds between snapshots and iterations is the number of times to produce the statistics, can be used to display real-time statistics.
The following are some typical sar command options:
-A
: All statistics-b
: I/O statistics-B
: Swap usage statistics-d
: I/O for each block device-n ALL
: All network statistics-q
: Processor queue (cache) statistics-r
: Memory and swap statistics-u
: CPU statistics (default)-v
: Kernel statistics-W
: Simplified swap statistics
5. free
The procps package, which comes with the free command, is present in the majority of Linux variants. The entire amount of used and free memory, along with the buffers and caches, are displayed when you run the free command without any arguments. This is an illustration of how to utilise the free command:
free -h
The output is rendered intelligible by humans thanks to the -h option, which displays sizes in gigabytes (G), megabytes (M), and kilobytes (K). This is very useful when working with huge memory sizes.
This is an illustration of how the result could appear:
total used free shared buff/cache available
Mem: 7.7G 1.2G 4.9G 116M 1.6G 6.0G
Swap: 2.0G 128M 1.9G