# this program was written by Philip Greenspun (philg@mit.edu) # it is free to everyone under the standard GNU Public License # park this in a file named monitor.tcl somewhere that AOLserver # can access it (note that you must have enabled Tcl pages to # have this work) set connections [ns_server active] # let's build an ns_set just to figure out how many distinct elts; kind of a kludge # but I don't see how it would be faster in raw Tcl set scratch [ns_set new scratch] foreach connection $connections { ns_set cput $scratch [lindex $connection 1] 1 } set distinct [ns_set size $scratch] # run standard Unix uptime command to get load average (crude measure of # system health) set uptime_output [exec uptime] ns_write $conn "HTTP/1.0 200 OK MIME-Version: 1.0 Content-Type: text/html Life on the [ns_info server] server

Life on the [ns_info server] server

There are a total of [llength $connections] requests being served right now (to $distinct distinct IP addresses). Note that this number seems to include only the larger requests. Smaller requests, e.g., for .html files and in-line images, seem to come and go too fast for this program to catch.

Here's what uptime has to say about the box:

" foreach connection $connections { ns_write $conn "
conn #client IPstatemethodurln seconds
[join $connection ]" } ns_write $conn "