Monitoring the output of 'top' command on hourly basis.

I need to capture the following data on an hourly basis through cronjob scheduling:-

  1. load averages
  2. Total no. of processes.
  3. CPU state
  4. Memory
  5. Top 3 process details.

All the above information is available through the command 'top'. But here we need to automate the same and save it in a log file for the purpose of monitoring the server performance.

Please find the below data which exactly I need to capture:-

 
load averages:  0.30,  0.29,  0.24                                          
90 processes:  88 sleeping, 2 on cpu
CPU states: 97.7% idle,  1.7% user,  0.6% kernel,  0.0% iowait,  0.0% swap
Memory: 16G real, 11G free, 3333M swap in use, 13G swap free
   PID USERNAME LWP PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
 29490 oms1      47   0   12  172M  140M cpu/0   55:40  0.75% java
  2436 sroy       1  59    0 7208K 6088K cpu/8    0:54  0.52% top
  2482 avijay     1  32    0 7080K 5960K sleep    0:01  0.26% top

Request you to please provide some idea or any automation script how the above activity can be performed.

Thank you all in advance.

---------- Post updated at 11:06 PM ---------- Previous update was at 10:54 PM ----------

Sorry for not mentioning, the requirement is for Solaris 10 environment.

i'll recommend SAR for doing this...

System Activity Reporter (sar)

1: `w|head -1`
2: `ps -e|wc -l`
3&4: `vmstat 1 2|tail -1`
5: `ps -elfy|sort +4n -r|head -3`

EDIT:
Duke is right, `sar` is the best way to do this.

Probably you can write a cron job which updates a log file as

top >> monitor.log

schedule it to run every 5 min or desired frequency.

This must help

# Run top every minute for 60 minutes
/usr/local/bin/top -c -s 60 -d 60 >> $TOPLOG