SAR command in Linux to monitor system performance

admin

sar (System Activity Report) It can be used đồ sộ monitor Linux system’s resources lượt thích CPU usage, Memory utilization, I/O devices consumption, Network monitoring, Disk usage, process and thread allocation, battery performance, Plug and play devices, Processor performance, tệp tin system and more. Linux system Monitoring and analyzing sida in understanding system resource usage which can help đồ sộ improve system performance đồ sộ handle more requests. 

By mặc định, the SAR command displays the result on the output screen, in addition, result can also be stored in the tệp tin specified by the -o filename option. 
Any user can collect information about system performance using system activity flags. The SAR command will show only CPU monitoring activity if any flag is not specified by the user. 

Installation of `sar` in Linux

`sar` may not be installed by mặc định. We need đồ sộ install `sysstat` before using it 

To install `sar` in Ubuntu

sudo apt install sysstat

To install `sar` in RedHat Linux (9)

Sudo dnf install sysstat

Syntax of `sar` command in Linux

sar -[ options ] time_interval number_of_tines_to_display

Examples and Options

To start `sar` Service 

Syntax:

systemctl start sysstat.service

Starting sar service

Starting sar service

`–help` option in `sar` command

Syntax:

sar --help

361

sar –help

We need đồ sộ enter the root password for authentication.

To verify the `sar` version

Syntax:

sar -V

version of sar

version of sar

CPU Usage Details

To report CPU details a total of 5 times with the interval of 2 seconds. If the interval command is mix đồ sộ zero, average statistics from the time system started are presented. If the count is not provided and the interval is given, statistics are provided continuously after every interval. 

Syntax:

sar -u 2 5

CPU Usage Details

CPU Usage Details

Memory Usage Details

To report about the amount of memory used, amount of memory không tính phí, available cache, available buffers total 3 times with the interval of 1 second. 

Syntax:

sar -r 1 3

Memory Usage

Memory Usage

File System Details

To report about tệp tin systems mounted on the device total 5 times with the interval of 2 seconds. 

Syntax:

sar -F 2 5

File system

File system

Block Device Details

To report about block devices details total 3 times with the interval of 1 second. 

Syntax:

Blocked Device

Blocked Device

Run Queue Length and Load Average

To report run rẩy queue length, number of processes and load average 

Syntax:

sar -q 2 5

Run Queue Length and average

Run Queue Length and average

CPU Usage for a Specific Core

To report cpu usage for given core

sar -P 1 1 3

CUP usage for a specific core

CUP usage for a specific core

Network Interface Details

To report about network interface, network tốc độ, IPV4, TCPV4, ICMPV4 network traffic and errors

Syntax:

 sar -n DEV 1 3 | egrep -v lo

Network Interface

Network Interface

Process, Kernel Thread, I-node, and File Table Details

To report details about the process, kernel thread, i-node, and the tệp tin tables 

Syntax:

sar -v 1 3

372

Messages, Semaphores, and Process Details

To report messages, semaphores and processes details for all processors and system-wide. 

sar -mu -P ALL

Swapping Statistics

To report statistics about swapping 

Syntax:

sar -S 1 3

Swapping Statistics

Swapping Statistics

I/O Operation Details

To report details about I/O operations lượt thích transaction per second, read per second, write per second.

syntax:

sar -b 1 3

375

I/O Operations Details

Context Switching, Process Creation, and Swap Details

To report statistics about context switching, number of processes created per second, number of swap per second .

sar -w 1 3

374

Paging Statistics

To report paging statistics (KBs paged-in/sec, KBs paged-out/sec, pagefault/sec etc.) 

sar -B 2 5

376

Paging Statics

Conclusion

In this article we discussed The SAR (System Activity Report) command in Linux is a powerful tool for monitoring and analyzing system resources. It provides detailed information on CPU usage, memory utilization, I/O devices, network monitoring, disk usage, and more. SAR helps system administrators and developers understand system performance, identify bottlenecks, and optimize resource allocation for improved efficiency and stability. It is an essential tool for managing and optimizing Linux systems.

SAR command in Linux đồ sộ monitor system performance – FAQs

What is the SAR command used for in Linux?

The sar (System Activity Report) command in Linux is used for collecting, reporting, and saving system activity information. It is a part of the sysstat package, which provides a mix of utilities for performance monitoring. sar is capable of reporting various system loads, such as CPU activity, memory/paging statistics, network, I/O, and more. It’s an invaluable tool for system administrators for historical data tracking or performance analysis, helping đồ sộ identify bottlenecks and optimizing system performance over time.

How đồ sộ install the SAR command on my system?

SAR is not installed by mặc định on most Linux systems but can be easily installed as part of the sysstat package. Here’s how you can install it:

On Debian/Ubuntu and derivatives:

sudo apt-get update
sudo apt-get install sysstat

On Red Hat/CentOS and derivatives:

sudo yum install sysstat

On Fedora:

sudo dnf install sysstat

After installation, you may need đồ sộ enable data collecting for sar by editing its configuration tệp tin, usually found at /etc/default/sysstat or /etc/sysconfig/sysstat, and ensure that data collection is enabled (e.g., ENABLED="true").

How đồ sộ use SAR đồ sộ monitor CPU usage?

To monitor CPU usage using sar, you can use the following command:

sar -u 1 5

This command tells sar đồ sộ display CPU usage statistics at 1-second intervals for a total of 5 times. Here’s a breakdown of the options:

  • -u: Reports CPU utilization.
  • The first number after the option (1) specifies the interval in seconds between two measurements.
  • The second number (5) specifies how many results đồ sộ show.

Each report line shows the CPU usage percentages for user, system, idle, and I/O wait time.

Can SAR be used đồ sộ kiểm tra memory usage?

Yes, sar can be used đồ sộ kiểm tra memory usage. Use the -r option đồ sộ display memory utilization statistics:

sar -r 1 5

This command displays memory stats (like kilobytes of used and không tính phí memory) every 1 second, repeating 5 times. This is helpful for monitoring how memory usage changes over time, particularly under different load conditions.

What are some common options for the SAR command?

SAR offers a multitude of options that can be tailored for various monitoring purposes. Some common options include:

  • -b: Reports I/O and transfer rate statistics.
  • -n DEV: Provides network statistics. You can specify further with DEV đồ sộ get detailed reports on specific network devices.
  • -d: Reports activity for each block device, useful for monitoring disk I/O.
  • -p: Makes the device names more readable (pretty).
  • -P ALL: Reports statistics for each processor individually in a multi-core system.
  • -f: Specifies a tệp tin from which đồ sộ retrieve the data. Useful for analyzing historical data, as sar can save data đồ sộ a tệp tin periodically.


Improve