Hack 96. Sar Command Examples

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.

*/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.

# 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

# sar –u

Linux 2.6.9-42.ELsmp (dev-db)        01/01/2009
12:00:01 AM  CPU  %user  %nice   %system   %iowait     %idle
12:05:01 AM  all  3.70    0.00      0.85      0.00     95.45
12:10:01 AM  all  4.59    0.00      1.19      0.06     94.16
12:15:01 AM  all  3.90    0.00      0.95      0.04     95.11
12:20:01 AM  all  4.06    0.00      1.00      0.01     94.93
12:25:01 AM  all  3.89    0.00      0.87      0.00     95.23
12:30:01 AM  all  3.89    0.00      0.87      0.00     95.23

Skipped..

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.

# sar -u -P ALL

Display Disk IO Statistics using sar command

# sar –d

Linux 2.6.9-42.ELsmp (dev-db)        01/01/2009
12:00:01 AM    DEV              tps    rd_sec/s  wr_sec/s
12:05:01 AM    dev2-0           1.65      1.28     45.43
12:10:01 AM    dev8-1          4.08      8.11     21.81

Skipped..

Average:       dev2-0           4.66    120.77     69.45
Average:       dev8-1          1.89      3.17      8.02

Display networking Statistics using sar command

# sar -n DEV | more

Linux 2.6.9-42.ELsmp (dev-db)        01/01/2009
12:00:01 AM     IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/
s  rxmcst/s
12:05:01 AM        lo      0.17      0.16     25.31     23.33      0.00      0.0
0      0.00
12:10:01 AM      eth0     52.92     53.64  10169.74  12178.57      0.00      0.0
0      0.00


# sar -n SOCK |more

Linux 2.6.9-42.ELsmp (dev-db)        01/01/2009
12:00:01 AM    totsck    tcpsck    udpsck    rawsck   ip-frag
12:05:01 AM        50        13         3         0         0
12:10:01 AM        50        13         4         0         0
12:15:01 AM        53        13         5         0         0

Comments on this entry are closed.