# this program was written by Philip Greenspun (philg@mit.edu) # it is free to everyone under the standard GNU Public License # Modified by Hugh Brock hbrock@arsdigita.com 3/30/00 so keepalive could # write monitor information into the server error log before restarting. 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) if [catch {set uptime_output [exec /usr/bin/uptime]} errmsg] { # whoops something wrong with uptime (check path) set uptime_output "ERROR running uptime, check path in script" } set connection_block "" foreach connection $connections { append connection_block "[join $connection " : "] " } ns_log error "Keepalive restarted the [ns_info server] server. Server status just before restart: 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. AOLserver says that the max number of threads spawned since server startup is [ns_totalstats HWM-threads]. The max threads since the last interval reset (every 5 minutes or so by default): [ns_intervalstats HWM-threads]. This final number is probably the best estimate of current server activity. Here's what uptime has to say about the box: $uptime_output conn # : client IP : state : method : url : n seconds : bytes $connection_block "