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:

OptionDescription
-AProvide you the all the statistics from current day 00:00:00 am to current time. With average of the statistics.
-bProvides you I/O and transfer rate statistics.
-BProvides 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

-CProvides 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

-dProvides 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

-eEnd time of the report. [should be 24 hour format]
Default end time is 18:00:00.SAR (System Activity Report) Installation, Commands and Guide
-fProvides you statistic report from the provide sa file.
SAR (System Activity Report) Installation, Commands and Guide
-hSAR options short help. All the SAR options will not be available with –h option.
SAR (System Activity Report) Installation, Commands and Guide
-iProvides statistic data as close to the specified interval, this option need to be used with option –f for better results.
-IProvides 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

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

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

-nProvides 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

-oProvides 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

-PProvides 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

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

SAR (System Activity Report) Installation, Commands and Guide

-qProvides the load average and the queue length.

SAR (System Activity Report) Installation, Commands and Guide

-rProvides memory utilization statistics.

SAR (System Activity Report) Installation, Commands and Guide

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

SAR (System Activity Report) Installation, Commands and Guide

-sHelps 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
-SProvides us the swap memory utilization stats. Like swap used, free and swap percentage etc.

SAR (System Activity Report) Installation, Commands and Guide

-tHelp 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

-vProvide 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

-VProvides us the sar version number details.

SAR (System Activity Report) Installation, Commands and Guide

-wProvides the system switching activity and task creation activity details.

SAR (System Activity Report) Installation, Commands and Guide

-WProvides us the swapping stats like number of page swaps brought in and out by the syatem.
-yProvides 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!

 

RELATED POSTS

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