System Administration Guide: Advanced Administration

Collecting System Activity Data Automatically (sar)

Three commands are involved in the automatic collection of system activity data: sadc, sa1, and sa2.

The sadc data collection utility periodically collects data on system activity and saves the data in a file in binary format, one file for each 24-hour period. You can set up the sadc command to run periodically (usually once each hour), and whenever the system boots to multiuser mode. The data files are placed in the /var/adm/sa directory. Each file is named sadd, where dd is the current date. The format of the command is as follows:


/usr/lib/sa/sadc [t n] [ofile]

The command samples n times with an interval of t seconds, which should be greater than 5 seconds between samples. This command then writes to the binary ofile file, or to standard output.

Running the sadc Command When Booting

The sadc command should be run at system boot time in order to record the statistics from when the counters are reset to zero. To make sure that sadc is run at boot time, the /etc/init.d/perf file contains a command line that writes a record to the daily data file.

The command entry has the following format:


/usr/bin/su sys -c "/usr/lib/sa/sadc /var/adm/sa/sa`date +%d`"

Running the sadc Command Periodically With the sa1 Script

To generate periodic records, you need to run the sadc command regularly. The simplest way to do so is uncomment the following lines in the /var/spool/cron/crontab/sys file:


# 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

The sys crontab entries do the following:

You can change these defaults to meet your needs.

Producing Reports With the sa2 Shell Script

Another shell script, sa2, produces reports rather than binary data files. The sa2 command invokes the sar command and writes the ASCII output to a report file.

Setting Up Automatic Data Collection (sar)

The sar command can be used either to gather system activity data itself or to report what has been collected in the daily activity files that are created by the sadc command.

The sar command has the following formats:


sar [-aAbcdgkmpqruvwy] [-o file] t [n] 

sar [-aAbcdgkmpqruvwy] [-s time] [-e time] [-i sec] [-f file]

The following sar command samples cumulative activity counters in the operating system every t seconds, n times. The t should be 5 seconds or greater. Otherwise, the command itself might affect the sample. You must specify a time interval between which to take the samples. Otherwise, the command operates according to the second format. The default value of n is 1. The following example takes two samples separated by 10 seconds. If the -o option is specified, samples are saved in binary format.


$ sar -u 10 2

Other important information about the sar command includes the following:

The following table lists the sar options and their actions.

Table 24–21 Options for the sar Command

Option 

Actions 

-a

Checks file access operations 

-b

Checks buffer activity  

-c

Checks system calls  

-d

Checks activity for each block device 

-g

Checks page-out and memory freeing  

-k

Checks kernel memory allocation  

-m

Checks interprocess communication  

-p

Checks swap and dispatch activity  

-q

Checks queue activity  

-r

Checks unused memory  

-u

Checks CPU utilization 

-nv

Checks system table status  

-w

Checks swapping and switching volume  

-y

Checks terminal activity  

-A

Reports overall system performance, which is the same as entering all options. 

If no option is used, it is equivalent to calling the command with the -u option.

How to Set Up Automatic Data Collection

  1. Become superuser.

  2. Edit the /etc/init.d/perf file and uncomment the following lines:


    # if [ -z "$_INIT_RUN_LEVEL" ]; then
    #       set -- `/usr/bin/who -r`
    #       _INIT_RUN_LEVEL="$7"
    #       _INIT_RUN_NPREV="$8"
    #       _INIT_PREV_LEVEL="$9"
    # fi
    # 
    # if [ $_INIT_RUN_LEVEL -ge 2 -a $_INIT_RUN_LEVEL -le 4 -a \
    #     $_INIT_RUN_NPREV -eq 0 -a \( $_INIT_PREV_LEVEL = 1 -o \
    #     $_INIT_PREV_LEVEL = S \) ]; then
    # 
    #       /usr/bin/su sys -c "/usr/lib/sa/sadc /var/adm/sa/sa`date +%d`"
    # fi

    This version of the sadc command writes a special record that marks the time when the counters are reset to zero (boot time).

  3. Edit the /var/spool/cron/crontabs/sys crontab file and uncomment the following lines:


    # 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