Introduction
The System Activity Report (SAR) is a powerful command-line tool available on most Linux distributions that enables system administrators to gather and analyze performance data over time. The sar command collects data on a variety of system resources, including CPU usage, memory utilization, disk I/O, network activity, and more. In this blog, will ‘ll cover the basic usage of sar command in Linux and provide examples of how to use it to monitor system performance. This is applicable on Red Hat Linux, Ubuntu and CentOS operating systems and supported command line shells.
Installation
The sar command is part of the sysstat package, which is available on most Linux distributions.
$ sudo apt-get install sysstat
For Installation on Red Hat Linux and Centos:
$ sudo yum install sysstat
After installation, the sar command will be available on your system.
Usage
The sar command collects system performance data at regular intervals and saves it to a file. By default, sar saves the data to the file /var/log/sysstat/saYYMMDD, where YYMMDD is the current date. To view the data, you can use the sar command with various options.
To display the CPU usage for the current day, run the following command:
$ sar -u
This will display a summary of CPU usage for each minute of the current day.
To display the memory usage of the current day, run the following command:
$ sar -r
This will display a summary of memory usage for each minute of the current day.
To display the disk I/O for the current day, run the following command:
$ sar -b
This will display a summary of disk I/O for each minute of the current day.
Furthermore, to display the network activity for the current day, run the following command:
$ sar -n DEV
This will display a summary of network activity for each minute of the current day, broken down by the network interface.
To display the process activity for the current day, run the following command:
$ sar -p
This will display a summary of process activity for each minute of the current day.
To display the load average for the current day, run the following command:
$ sar -q
This will display a summary of the system load average for each minute of the current day.
By default, sar displays data for the current day. To view data for a specific day, you can use the -f option followed by the path to the sar file. For example, to display data for April 15th, 2023, run the following command:
$ sar -u -f /var/log/sysstat/sa230415
Conclusion
The sar command is a powerful tool, especially, for monitoring system performance on Linux. By collecting data at regular intervals, sar enables system administrators to identify trends and potential issues before they become critical. The examples provided in this article should help you get started with using sar to monitor your Linux systems and effective usage of sar command in Linux.