SAR (System Activity Report) Installation, Commands and Guide A useful tutorial guide to the SAR (System Activity Result) tool, available for any Linux or Unix distribution: Debian, Ubuntu, CentOS, RHEL and more!

Linux - Come inviare E-Mail con sSMTP (con configurazioni-tipo per GMail, Aruba e Yahoo)

If you are a system administrator/Tester/Developer it's important for you to monitor your system health. If you are a Tester/Developer you need to understand how much memory or CPU is getting used by the application over a period of time. But it is difficult to monitor the system stats throughout the day or days. There is a simple tool/application named SAR (System Activity Report) available for collecting CPU, Memory, I/O stats and analyze, Of-course this can be used only for linux, unix or ubuntu machines.

Why SAR?

If you are working on linux machine you will know that you need to use different commands/tools to get different usage reports, such as: -top for CPU usage, -free for memory usage etc.

But SAR will provide you all the resource usage data which can be fetched from different tools and also this reports will generate in daily basis which can be used for historical data analysis at any time.

SAR (System Activity Report) Installation, Commands and Guide

Advantages of using SAR

  • Cumulative stats data will be available.
  • Continuous monitoring of system stats.
  • Able to fetch system stats at any point of time.
  • Daily System performance will get captured. For 30 days
  • No need of manual intervention for collecting stats.
  • Quick stats overview at any given time.
  • 24 hours system stats will get collected.

SAR Installation

We can install SAR stats pretty easily. Use the following commands to install.

Can be installed using yum install. [Note:- make sure yum repository configured]

Or it can be installed using apt get [Mostly this can be used for ubuntu]

Or by downloading SAR rpm package. [It’s recommended that, install latest version or the SAR package version which supported to your RHEL or CentOS version]

You can check the version of SAR package installed or already available in you system by below command.

Collecting SAR reports using cron job

Open the sysstat file available at /etc/cron.d/ :

and configure the cron job as shown below:

For specific duration, first cron configuration will be used as shown in example. As shown in above example cron will run every 10 min and collect the stats and dump into a log file named sa followed by current day under /var/log/sa location. [ex:- today 20/06/2018, SAR output file will be sa20].

For daily summary of STATS report will get captured using second cron configuration, based on cron configuration every day at 11:23 PM [i.e at 23:53] summary of that day STATS report will get captured and dump into a log file named sar followed by current day under /var/log/sa location. [ex:- today 20/06/2018, SAR output file will be sar20].

If we want to collect the stats for every one min, cron job should be configured as shown below.
[Note:- min value to get the stats is 1 min, we cannot go min value then this as cron limits us to configure to min value as 1]

In case of Ubuntu, For enabling SAR we need to enable the sadc (system activity data collector) under sysstat file, present under following location /etc/default/ change the property ENABLE to true.

Configurations for SAR

We can configure our custom configurations in sysstat file under /etc/sysconfig/ like below.
[These configurations are optional].

  • How long to keep log files (in days).
  • Compress sa and sar files older than (in days).
  • Parameters for the system activity data collector for the generation of log files.
  • Compression program to use. [either gzip or bzip2]

SAR commands to get the performance report

Before going to sar command usage, Lets see what are the SAR command options available. All option may not be used all the time, but we can see usage of those option with some description.

SAR (System Activity Report) Installation, Commands and Guide

Retrieving the stats using SAR

If you want to see the current CPU statistics here is the below example.

In below example we are trying to retrieve the current CPU usage of ALL CPUs.

SAR (System Activity Report) Installation, Commands and Guide

Explanation

  • sar –P provides us the CPU usage, if we add ALL to this command we can get the ALL CPU usage. [Above example we have 4 CPUs]
  • Option 2 means we need the CPU data every 2 seconds.
  • Option 3 means instructing that we need all CPU data every 2 seconds print for 3 iterations/ 3 times.

SAR (System Activity Report) Installation, Commands and Guide

SAR options with explanation:

Option Description
-A Provide you the all the statistics from current day 00:00:00 am to current time. With average of the statistics.
-b Provides you I/O and transfer rate statistics.
-B Provides you paging statistics, like sadc

  • Per second how many number of KBs the system paged in from disk.
  • Per second how many number of KBs (kilobytes) the system paged out from disk.
  • No of pages on the free list by system.
  • No of pages that are scanned per second and more.

SAR (System Activity Report) Installation, Commands and Guide

-C Provides commands that are inserted by using sadc when reading data from file. [All CPU avg will be available from current day 00:00:00 am to current time].

SAR (System Activity Report) Installation, Commands and Guide

-d Provides disk activities depending on sadc like –S DISK and –S XDISK that need to collected. Output will provide us

  • No of transactions per second.
  • No of reads from device.
  • No of writes to the device.
  • Avg size of requests.
  • Time taken to request form queue.
  • CPU % time during Input/Output requests. Etc...

SAR (System Activity Report) Installation, Commands and Guide

-e End time of the report. [should be 24 hour format]
Default end time is 18:00:00.SAR (System Activity Report) Installation, Commands and Guide
-f Provides you statistic report from the provide sa file.
SAR (System Activity Report) Installation, Commands and Guide
-h SAR options short help. All the SAR options will not be available with –h option.
SAR (System Activity Report) Installation, Commands and Guide
-i Provides statistic data as close to the specified interval, this option need to be used with option –f for better results.
-I Provides Interrupts statistics of current day , these stats are collected based on sadc option –S INT. if sadc option –S INT is not collected the you can see not available output.

SAR (System Activity Report) Installation, Commands and Guide

-m Provides power management statistics based on the sadc option –S OPTIONS.

Ex:- sar –m { keyword [,…] | ALL }

-n Provides network statistics.

Ex:- sar –n { keyword [,…] | ALL }

Possible keywords for –n option

DEV, EDEV, NFS, NFSD, TCP, ETCP, UDP, SOCK6, IP6, EIP6, ICMP6, SOCK, IP, EIP, ICMP, EICMP, EICMP6 and UDP6

SAR (System Activity Report) Installation, Commands and Guide

-o Provides the functionality to save the readings in the file in binary format. –o option is exclusive for –f option.

SAR (System Activity Report) Installation, Commands and Guide


Accessing the saved file using the option - f.

SAR (System Activity Report) Installation, Commands and Guide

-P Provides you the statistics of the processor or processors, if we provide ALL keyword provides individual processor statistics.

SAR (System Activity Report) Installation, Commands and Guide

-p It prints the device names, -p option should be used with –d.

SAR (System Activity Report) Installation, Commands and Guide

-q Provides the load average and the queue length.

SAR (System Activity Report) Installation, Commands and Guide

-r Provides memory utilization statistics.

SAR (System Activity Report) Installation, Commands and Guide

-R Provides the memory statistics like buffer pages used, cached and free pages.

SAR (System Activity Report) Installation, Commands and Guide

-s Helps you to set the starting time for collecting data. [Should be 24 hour format].
Default end time is 08:00:00.SAR (System Activity Report) Installation, Commands and Guide
-S Provides us the swap memory utilization stats. Like swap used, free and swap percentage etc.

SAR (System Activity Report) Installation, Commands and Guide

-t Help us while reading the daily data file in original local time.

SAR (System Activity Report) Installation, Commands and Guide

-u Provide you all CPU utilization stats from 00:00:00 timestamp of current day. If we use ALL keyword it will display all CPU fields.

SAR (System Activity Report) Installation, Commands and Guide

Using ALL keyword:

SAR (System Activity Report) Installation, Commands and Guide

-v Provide the stats about file, inode and kernel tables. Provides us details like number unused cache details, number of file handles and inode handlers used by system etc.

SAR (System Activity Report) Installation, Commands and Guide

-V Provides us the sar version number details.

SAR (System Activity Report) Installation, Commands and Guide

-w Provides the system switching activity and task creation activity details.

SAR (System Activity Report) Installation, Commands and Guide

-W Provides us the swapping stats like number of page swaps brought in and out by the syatem.
-y Provides us the TTY device activity details.

SAR (System Activity Report) Installation, Commands and Guide

So far we saw about the options used with SAR command, we can use the combination of all the above options please find the sample examples as below:

SAR (System Activity Report) Installation, Commands and Guide

That's about it: hope you'll find this reference guide useful enough!

 

About Teju NC

An experienced, enthusiastic and passionate Sr. Software Engineer with a great desire for continued professional and personal growth. As a testing engineer, I have supported and led many exciting and challenging projects for great companies. Currently associated with MindMajix Technologies, specialist in Mobile and Web application testing great experience in working with HTML4/5, CSS, MVC, jQuery, Ajax, JavaScript, React JS, Node JS, Jenkins, JBoss, Mongodb, Python, Bootstrap, SAR, SIP Testing Tools, ISTQB, Data Science and other technology testing tools. I love working on linux machines and write articles and tutorials about their usage.

View all posts by Teju NC

One Comment on “SAR (System Activity Report) Installation, Commands and Guide A useful tutorial guide to the SAR (System Activity Result) tool, available for any Linux or Unix distribution: Debian, Ubuntu, CentOS, RHEL and more!

  1. Great tutorial. You could also analyze sar report to get charts and aggregated data. For that we can follow https://github.com/sumitbiswasgit/sarbox

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

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