How to use sar command?


This article describes how to use “sar” command  to analyse system performance in Unix and Linux especially Oracle Solaris.We’ll describe sar command and parameters with examples. By  default sar package comes from Oracle Solaris and HP-UX installation but for linux you have to install sysstat package.

Which  performance statistics you can monitor  with  sar  command ?

  • CPU usage and statistics
  • Memory  usage and statistics
  • Swap  usage and statistics
  • I/O activities  for the  system
  • Context  switch statistics
  • Run queue and load  avarage
  • Network statistics
  • Report all data  for a spesific  time

According to sysstat package describtion  it  includes  following system analyze packages;

sar pidstat
iostat sadf
mpstat  

You can monitor system performance in real time and also for the past.Let’s check how to install systat package for all type of linux server:

SAR Installation

Ubuntu:

sudo apt-get install sysstat

Centos/Fedora/Red Hat:

yum install sysstat

or

rpm -ivh sysstat-10.xx.rpm

And also you can get sysstat binary file from this SITE and install them on your server. You can download sysstat binary  file to your  local and put it them to the server with  SFTP .Filezilla can be use for file transfer from your local to server.

After you put sysstat bz file under a directory  then you can apply these commands .Also read install file to check if you need more.But I recommend you to put “enable-install-cron” option while configure .This option  ‘ll create startup file and also cron file for you.(/etc/rc.d/init.d/sysstat)

#tar xvfj sysstat-11.1.8.tar.bz2
cd sysstat-11.1.8
./configure --enable-install-cron
#make
#make install
Enable  data  collection on SAR

Take a  look this  Link.You ‘ll get a script to run on your servers.The script  which added  checks and  performs all changes for you. Please  first  run  script  on your test server then check  if everything is fine then  perform same operation for other servers.

After you enabled sar data collection  it ‘ll collect  all performance data. These  files  will be  located  under  the  directory which I added  below.

Oracle  Solaris:/var/adm/sa

HP-UX:/var/adm/sa

Linux:/var/log/sa

Command  Usage for  a spesific  time:”-s” start time  “-e” end time

#sar  -A -f  /var/log/sa/sar13 -s 16:00:00 -e 17:00:00

Oracle Solaris:

  • Service:
    • svcadm enable system/sar:default
      
  • Crontab:
    • ## crontab -e sys
      
      0 * * * 0-6 /usr/lib/sa/sa1
      
      20,40 8-17 * * 1-5 /usr/lib/sa/sa1
      
      5 18 * * 1-5 /usr/lib/sa/sa2 -s 8:00 -e 18:01 -i 1200 -A
      
      

Linux:

  • Install  sysstat package
  • Service:
#cat /etc/sysconfig/sysstat
# How long to keep log files (days), maximum is a month
HISTORY=7
  • Crontab:
[root@testserver ~]# cat /etc/cron.d/sysstat
# run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib64/sa/sa1 1 1
# generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib64/sa/sa2 -A

HP-UX:

  • Be sure  /var/adm/sa  directory exist
  • Crontab:
echo "0 * * * 0,6 /usr/lbin/sa/sa1" >> /usr/spool/cron/crontabs/root
echo "0 8-17 * * 1-5 /usr/lbin/sa/sa1 300 3" >> /usr/spool/cron/crontabs/root
echo "0 18-7 * * 1-5 /usr/lbin/sa/sa1" >> /usr/spool/cron/crontabs/root

Use  SAR Command

Oracle  Solaris

Memory  Usage Controls:

  • How  to check  page-out and  memory with sar  for  oracle solaris?
    • There are two  important  parameters  that  you need to check  if system needs  more  memory.
      Observed  high values at the same time for the pgscan/s and  pgfree/s, indicates a memory shortage. Please  run “ps  -elf|grep  -v  grep |egrep ‘PID|page'” and check  number  of cycle  for  page  deamon.
    • “sar  -g” also  shows  information about inodes  recycle  state. Check  if  inodes  being  recycled too quickly.Recycled inodes  can be cause  of  loss of reusable  pages.
casesup@solaris:~$ sar  -g  1 3
SunOS solaris 5.11 11.2 i86pc    10/31/2015
11:29:00  pgout/s ppgout/s pgfree/s pgscan/s %ufs_ipf
11:29:01     0.00     0.00     0.00     0.00     0.00
11:29:02     0.00     0.00     0.00     0.00     0.00
11:29:03     0.00     0.00     0.00     0.00     0.00
Average      0.00     0.00     0.00     0.00     0.00
  • How  to check Kernel memory usage with sar  for  oracle solaris?
casesup@solaris:~$ sar  -k 1 20
SunOS solaris 5.11 11.2 i86pc    10/31/2015
11:45:19 sml_mem   alloc  fail  lg_mem   alloc  fail  ovsz_alloc  fail
11:45:20 332820736 202341008 16070 3998171136 3228714496     0   100196352     0
11:45:21 332820736 202341264 16070 3998171136 3228714496     0   100196352     0
11:45:22 332820736 202341200 16070 3998171136 3228714496     0   100196352     0
11:45:23 332820736 202341088 16070 3998171136 3228714496     0   100196352     0
11:45:24 332820736 202341152 16070 3998171136 3228714496     0   100196352     0
11:45:25 332820736 202341120 16070 3998171136 3228714496     0   100196352     0
  • How  to check Page-In activity with sar  for  oracle solaris?


 

casesup@solaris:~$ sar  -p 1 100
SunOS solaris 5.11 11.2 i86pc    10/31/2015
11:49:26  atch/s  pgin/s ppgin/s  pflt/s  vflt/s slock/s
11:49:27   20.59    0.00    0.00   56.86  189.22    0.00
11:49:28   42.42    0.00    0.00   52.53  179.80    0.00
11:49:29   42.00    0.00    0.00   52.00  176.00    0.00
  • How to Check Queue Activity with sar  for  Oracle  Solaris?
    • runq-sz:The  number  of  process  waiting for free  Cpu .This value  must be less then 2.
casesup@solaris:~$ sar  -q 1 100
SunOS solaris 5.11 11.2 i86pc    10/31/2015
11:54:38 runq-sz %runocc swpq-sz %swpocc
11:54:39     0.0       0     0.0       0
11:54:40     0.0       0     0.0       0
11:54:41     0.0       0     0.0       0
11:54:42     0.0       0     0.0       0
  • How to Check Free  memory  with sar  for  Oracle  Solaris?
    • Freeswap:freeswap*512  bytes
	
#pagesize
4096
casesup@solaris:~$ sar  -r  1 100
SunOS solaris 5.11 11.2 i86pc    10/31/2015
11:57:26 freemem freeswap
11:57:27  435698  6381072
11:57:28  435697  6381072
11:57:29  435699  6381072
11:57:30  435700  6381072
  • How to check  swap activity with sar  for  Oracle Solaris?
    • swpot/s:The avarage  number of  process swapped  out. This  is  too critical. You need to check  if  it’s  bigger then “1”. Then  you need to  increase  system memory.

CPU Usage Controls:

  • How to check  Idle  CPU  with sar  for  Oracle Solaris?
    •  “sar -u”  command shows the  processors  is either  busy   or  free.When processor is busy it  means  that  the  processor  is  in either  user mode or system  mode. I  remommend to  check first  idle  cpu if   it’s  too  low  then  check  system mode  or  user mode.
      • %usr:User mode
      • %sys:System  mode
      • %wio:Waiting  for  I/O
      • %idle:Idle  not waiting  for  I/O 
casesup@solaris:~$ sar  -u  1 10
SunOS solaris 5.11 11.2 i86pc    11/01/2015
08:10:07    %usr    %sys    %wio   %idle
08:10:08       5      14       0      81
08:10:09       6      18       0      76
08:10:10       4       2       0      94
08:10:11       4       2       0      94

Disk Usage Controls:

  • How to check disk service time  or utulization with sar command  for Oracle Solaris?
    • avserv:Avarage time,in milisecond, that  I/O request wait for  idle  in the queue.
    • avwait :Avarage time,in milisecond, that  I/O request  to be completed  by disk device.This  is importand and  also depends  on your  Storage luns. For  mission critical systems and  SSD disk this  parameter can be  observed  max “10”.
casesup@solaris:~$ sar  -d 1 100
SunOS solaris 5.11 11.2 i86pc    11/01/2015
08:27:34   device        %busy   avque   r+w/s  blks/s  avwait  avserv
08:27:35   ata1              0     0.0       0       0     0.0     0.0
iscsi0            0     0.0       0       0     0.0     0.0
mpt0              1     0.0      71    2367     0.0     0.5
scsi_vhc          0     0.0       0       0     0.0     0.0
sd0               1     0.0      73    2367     0.0     0.5
sd0,a             0     0.0       2       0     0.0     0.0
sd0,b             1     0.0      71    2367     0.0     0.5
sd0,h             0     0.0       0       0     0.0     0.0
sd0,i             0     0.0       0       0     0.0     0.0
sd0,q             0     0.0       0       0     0.0     0.0
sd0,r             0     0.0       0       0     0.0     0.0
sd1               0     0.0       0       0     0.0     0.0

I'm a IT Infrastructure and Operations Architect with extensive experience and administration skills and works for Turk Telekom. I provide hardware and software support for the IT Infrastructure and Operations tasks.

205 Total Posts
Follow Me