Hack 96. Sar Command Examples

by Ramesh

Sar commands comes with the sysstat package. Make sure sysstat is installed. If you don’t have sar installed on your system, get it from Sysstat project.Sar is an excellent monitoring tool that displays performance data of pretty much every resource of the system including CPU, memory, IO, paging, networking, interrupts etc.,Sar Collects, Reports (displays) and Saves the performance data. Let us look at all the three aspects separately

Sadc – System activity data collector

/usr/lib/sadc (System activity data collector) command collects the system data at a specified time interval. This uses the daily activity data file that is located under /va/log/sa/sa[dd], where dd is the current day.

Sa1 shell-script

/usr/lib/sa1 in-turn calls the /usr/lib/sadcs. sa1 is invoked from the crontab as shown below. Run this every 5 minutes or 15 minutes depending on your need. I prefer to schedule it for every 5 minutes in the cron tab as shown below.

  1. */5 * * * * root /usr/lib/sa/sa1 1 1

Sa2 shell-script

/usr/lib/sa2 is a shell script that will write a daily report in the /var/log/sa/sa[dd] file, where dd is the current day. Invoke the sa2 from the crontab once a day at midnight.

  1. # 59 23 * * * root /usr/lib/sa/sa2 –A

Note: /etc/cron.d/sysstat files comes with the sysstat package that includes some default value for the sa1 and sa2, which you can change accordingly.

Display CPU Statistics using Sar Command

  1. # sar –u
  2.  
  3. Linux 2.6.9-42.ELsmp (dev-db) 01/01/2009
  4. 12:00:01 AM CPU %user %nice %system %iowait %idle
  5. 12:05:01 AM all 3.70 0.00 0.85 0.00 95.45
  6. 12:10:01 AM all 4.59 0.00 1.19 0.06 94.16
  7. 12:15:01 AM all 3.90 0.00 0.95 0.04 95.11
  8. 12:20:01 AM all 4.06 0.00 1.00 0.01 94.93
  9. 12:25:01 AM all 3.89 0.00 0.87 0.00 95.23
  10. 12:30:01 AM all 3.89 0.00 0.87 0.00 95.23
  11.  
  12. Skipped..
  13.  
  14. Average: all 4.56 0.00 1.00 0.15 94.29

Note: If you need a break down of the performance data for the individual CPU’s, execute the following command.

  1. # sar -u -P ALL

Display Disk IO Statistics using sar command

  1. # sar –d
  2.  
  3. Linux 2.6.9-42.ELsmp (dev-db) 01/01/2009
  4. 12:00:01 AM DEV tps rd_sec/s wr_sec/s
  5. 12:05:01 AM dev2-0 1.65 1.28 45.43
  6. 12:10:01 AM dev8-1 4.08 8.11 21.81
  7.  
  8. Skipped..
  9.  
  10. Average: dev2-0 4.66 120.77 69.45
  11. Average: dev8-1 1.89 3.17 8.02

Display networking Statistics using sar command

  1. # sar -n DEV | more
  2.  
  3. Linux 2.6.9-42.ELsmp (dev-db) 01/01/2009
  4. 12:00:01 AM IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/
  5. s rxmcst/s
  6. 12:05:01 AM lo 0.17 0.16 25.31 23.33 0.00 0.0
  7. 0 0.00
  8. 12:10:01 AM eth0 52.92 53.64 10169.74 12178.57 0.00 0.0
  9. 0 0.00
  10.  
  11.  
  12. # sar -n SOCK |more
  13.  
  14. Linux 2.6.9-42.ELsmp (dev-db) 01/01/2009
  15. 12:00:01 AM totsck tcpsck udpsck rawsck ip-frag
  16. 12:05:01 AM 50 13 3 0 0
  17. 12:10:01 AM 50 13 4 0 0
  18. 12:15:01 AM 53 13 5 0 0