How To Install And Use Sar On Linux

Are you looking to optimize your system’s performance and keep track of resource usage? Look no further than SAR, the System Activity Reporter.

SAR (System Activity Report) is a versatile tool for monitoring various resources on a Linux system, including CPU usage, memory utilization, I/O device consumption, network activity, disk usage, process and thread allocation, battery performance, plug-and-play devices, processor performance, file system usage, and more.

By monitoring and analyzing these aspects, Linux system administrators can gain valuable insights into resource usage patterns. It enables them to optimize system performance and manage resources effectively to handle increased workloads.

By default, the SAR command displays results on the output screen. However, using the—o filename option, results can also be stored in a specified file.

Users can gather system performance data using system activity flags. The SAR command will display only CPU monitoring activity if no flags are specified.

To install and use sar on Linux, you may need to install sysstat first, as sar may not be included by default.

Requirements

  • A server running Ubuntu 22.04
  • User privileges: Either root access or a non-root user with sudo privileges

Step 1. System Update

If you’re working with a fresh installation of Ubuntu 22.04, updating the package repository is essential to ensure you have access to the latest versions.

Check By Using The Command Below :

sudo apt-get update -y && sudo apt-get upgrade -y

Step 2: Install SAR

By default, the SAR package is included in the sysstat package. To install SAR, execute the following command:

sudo apt-get install sysstat

After installation, start and enable the service using the command below:

sudo systemctl enable sysstat && sudo systemctl start sysstat

Verify if the service is active and running using the command below:

sudo systemctl status sysstat

Step 3: Enabling SAR

After installation, SAR is not enabled by default.

To enable it, open the /etc/default/sysstat file utilizing your preferred text editor, change ENABLED=”false” to ENABLED=”true,” and save the file.

It ensures that SAR starts monitoring your system’s activity immediately.

sudo vi /etc/default/sysstat

Then, restart the service by using the command below:

sudo systemctl restart sysstat

As mentioned earlier, SAR collects data every 10 minutes. You can verify this by checking the /etc/cron.d/sysstat file.

Step 4: Using SAR

Syntax of sar command

sar -[options] time_interval number_of_times_to_display

To check the version of sar, use the following command:

sar -V

CPU Usage Details

Generate CPU usage reports five times with a 2-second interval. If the interval is set to zero, average statistics from system startup are displayed. If no count is provided but an interval is specified, statistics are continuously offered at the specified interval.

To check CPU usage, execute the below command:

sar -u 2 5

Memory Usage Details

Display information about memory usage, including used memory, free memory, available cache, and available buffers, three times with a 1-second interval.

To check memory usage, execute the below command:

sar -r 1 3

File System Details

Display information about file systems mounted on the device five times with a 2-second interval.

To check file system details, execute the below command:

sar -F 2 5

CPU Usage for a Specific Core

Report the CPU usage for a specified core using the command below.

sar -P 1 1 3

Network Interface Details

Display information regarding network interfaces, including network speed, IPV4, TCPV4, ICMPV4 network traffic, and any associated errors.

To check Network Interface Details, execute the below command:

sar -n DEV 1 3 | egrep -v lo

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

Report information about processes, kernel threads, I-nodes, and file tables.

sar -v 1 3

Swapping Statistics

Report swapping statistics.

sar -S 1 3

Context Switching, Process Creation, and Swap Details

To report statistics on context switching, the rate of process creation per second, and the number of swaps per second.

sar -w 1 3

Conclusion

In summary, installing and utilizing SAR on Linux offers a powerful means of monitoring system performance and resource utilization.

Following the steps provided in this blog, users can gain valuable insights into their system’s behaviour and optimize its efficiency.

SAR is an essential tool for system administrators and users, providing valuable information for maintaining system health and performance.

(Visited 54 times, 1 visits today)

Leave a Reply

AlphaOmega Captcha Classica  –  Enter Security Code
captcha      
 

This site uses Akismet to reduce spam. Learn how your comment data is processed.