How to install and Use the SAR tool in Linux

Category : Linux/ Unix

install-sar-tool-in-linux

The System Activity Reporter, or SAR tool, is a powerful monitoring tool in Linux that allows you to collect and analyze historical system performance data. It is part of the sysstat package and provides valuable insights into CPU usage, memory utilization, disk I/O, network traffic, and more. In this article, we’ll walk through how to install SAR tool on various Linux distributions and demonstrate some basic usage examples.

Installing SAR tool

The process of installing SAR varies slightly depending on your Linux distribution. Here are the steps for some popular distros:

Ubuntu/Debian

sudo apt update
sudo apt install sysstat

CentOS/RHEL

sudo yum install sysstat

Fedora

sudo dnf install sysstat  

After installation, start and enable the sysstat service:

sudo systemctl start sysstat
sudo systemctl enable sysstat

Verify SAR is installed by checking the version:

sar -V

Basic Usage of SAR tool

SAR collects data at 10-minute intervals by default. You can view CPU utilization for the current day with:

sar -u 

To see memory usage instead:

sar -r

For disk I/O statistics:

sar -b

And for network traffic:

sar -n DEV

To display queue length and load averages, use:

sar -q

This command reports the run queue length (runq-sz), number of tasks in the task list (plist-sz), and system load averages for the last 1, 5, and 15 minutes (ldavg-1, ldavg-5, ldavg-15). Higher numbers indicate a more heavily loaded system.

You can also specify a custom interval and number of reports. For example, to display 3 reports of CPU usage at 2 second intervals:

sar -u 2 3

SAR stores its daily data files in the /var/log/sa/ directory. To read data from a previous day:

sar -f /var/log/sa/sa02

This would analyze data from the 2nd day of the month.

Conclusion

The SAR tool provides an wealth of performance metrics to help you monitor and optimize your Linux systems. Installing it is straightforward using your distribution’s package manager. By leveraging SAR’s reporting capabilities, including CPU usage, memory utilization, disk I/O, network traffic, and load averages, you can identify resource bottlenecks, analyze trends over time, and keep your systems running smoothly.