CS501

MP9 - Whos Using?


Introduction

In this MP* you will create a shell script that will generate a web page summarizing how the system resources are being used.

Background

A shell scipt has been created that generates a summary of the utilization of the system processor. This script uses a utility called mystats (available here) that reports per-processor statistics in tabular form. The script is shown below:



  1. #!/bin/sh
  2. mpstat 1 2 | tail -1 > /tmp/mpstats
  3. date > /tmp/mpdates
  4. chmod 744 /tmp/mpstats
  5. chmod 744 /tmp/mpdates
  6. # the infinite loop
  7. while [ 1 ]
  8. do
  9. mpstat 1 2 | tail -1 >> /tmp/mpstats
  10. date >> /tmp/mpdates
  11. tail -120 /tmp/mpdates | grep "^" > /tmp/mpdates
  12. tail -120 /tmp/mpstats | grep "^" > /tmp/mpstats
  13. sleep 30
  14. done

The script generates two files:

/tmp/mpstats - this file contains processor statistics collected every 30 seconds for 1 second. The file contains at a maximum 1 hours worth (120 entries) of processor statistics.

/tmp/mpdates - this file contains the date and time each of the values in /tmp/mpstats was collected. Maximum of 120 entries.

The format of the files is as follows.

/tmp/mpstats

Tue Mar 16 18:21:03 CST 1999
Tue Mar 16 18:21:35 CST 1999
...
Tue Mar 16 19:22:36 CST 1999
Tue Mar 16 19:23:07 CST 1999

/tmp/mpstats

  0   41   0    0   250   49  202   75    0    0    0  2899   96   3   0   1
  0   41   0    0   215   15   81   32    0    0    0  2242   98   2   0   0
...
  0   42   0    0   240   37  103   38    0    0    0  2143   96   4   0   0
  0   41   0    0   353  140  103   39    0    0    0  2406   97   3   0   0

The columns of interest are the last four in the /tmp/mpstats file. These columns contain the following information:

usr - percent user time
sys - percent system time
wt - percent wait time
idl - percent idle time

The Task

  1. Create a script (using the Bourne shell) that generates a web page that summarizes the processor utilization during the last hour (using all 120 statistics). The page you are to generate should look like the sample below.
  2. My solution to this problem used the colrm, paste, tail and sort commands among others. You may also need to create some temporary files. Look here for some ideas on creating temporary files.
  3. "Spiffy" formatting of the log contents yields bonus points.
  4. Note, you do not need to start the mystats program yourself. Please let you instructor know if the mystats program is not running and he will fire it up.

What You Will Turn In

A sheet containing your name, assignment number, course name, link to cgi/bin script (like http://mathcssun(1).emporia.edu/~ppalmsha/mp9.cgi) and a listing the script.

Example Web Page


* this exercise based on a suggestion by Jeff Doering