This post outlines steps to set up a cron job for automatic data collection from system activity reporter (aka SAR).
Prior to Solaris 10
1. Become the superuser.
2. Edit the following file:
# vi /etc/init.d/perf
3. Uncomment the following lines (remove the # sign from the beginning of each line):
#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
The sadc command creates a daily system activity file called sadd, where dd is the current day of the month. At boot time, the sadc command writes a special record that marks the time when the counters are set to zero.
4. Edit the system crontab file:
# crontab -e sys
5. Uncomment or create the following lines:
0 * * * 0-6 /usr/lib/sa/sa1 20,40 8-17 * * 1-5 /usr/lib/sa/sa1
Here,
– The first entry writes a record to /var/adm/sa/sadd (sa01, sa02, …) on the hour, every hour, seven days a week.
– The second entry writes a record to /var/adm/sa/sadd twice every hour during peak working hours: at 20 minutes and 40 minutes past the hour from 8 am to 5 pm Monday through Friday. Modify this entry as desired.
6. Execute the /etc/init.d/perf script, or reboot the system so that the files are re-read and started.
For Solaris 10 and higher
1. Become superuser.
2. Activate the sar service:
# svcadm enable system/sar
3. Edit the sys crontab file:
# crontab -e sys
4. Uncomment or create the following lines as needed:
0 * * * 0-6 /usr/lib/sa/sa1 20,40 8-17 * * 1-5 /usr/lib/sa/sa1
– The first entry writes a record to /var/adm/sa/sadd (sa01, sa02, …) on the hour, every hour, seven days a week.
– The second entry writes a record to /var/adm/sa/sadd twice every hour during peak working hours: at 20 minutes and 40 minutes past the hour from 8 am to 5 pm Monday through Friday. Modify this entry as desired.
5. Run sar to verify operation.
# sar SunOS berkeley 5.10 Generic sun4u 03/11/2005 17:35:22 %usr %sys %wio %idle 17:35:22 unix restarts 17:40:00 1 1 0 99 17:50:00 0 1 0 99 Average 0 1 0 99