Index: openacs-4/packages/monitoring/tcl/stats-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/tcl/stats-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/tcl/stats-procs.tcl 28 Aug 2007 12:59:28 -0000 1.1 @@ -0,0 +1,690 @@ +namespace eval monitoring {} + +proc monitoring::header {{stat ""}} { + if [string length $stat] { + set title "AOLserver Stats: [ns_info hostname] - $stat" + set nav "Main Menu > $stat" + } else { + set title "AOLserver Stats: [ns_info hostname]" + set nav "Main Menu" + } + set server [lindex [lindex [util_ns_set_to_list -set [ns_configsection ns/servers]] 0] 0] + set address [ns_config ns/server/${server}/module/nssock address ""] + return "\ + + + + + + + + +
$navServer: $address[monitoring::fmtTime [ns_time]]
+
" +} + +proc monitoring::footer {} { + return "" +} + +proc monitoring::adp {} { + set col [ns_queryget col 1] + set reverseSort [ns_queryget reversesort 1] + + set numericSort 1 + set colTitles [list File Device Inode "Modify Time" "Ref Count" Evals Size Blocks Scripts] + + if {$col == 1} { + set numericSort 0 + } + + set results "" + + foreach {file stats} [ns_adp_stats] { + set s "" + + foreach {k v} $stats { + if {[string match mtime $k]} { + lappend s [monitoring::fmtTime $v] + } else { + lappend s $v + } + } + lappend results [concat $file $s] + } + + set rows [monitoring::sortResults $results [expr $col - 1] $numericSort $reverseSort] + + set html [monitoring::header ADP] + append html [monitoring::results $col $colTitles adp $rows $reverseSort] + append html [monitoring::footer] + + return $html +} + +proc monitoring::cache {} { + set col [ns_queryget col 1] + set reverseSort [ns_queryget reversesort 1] + + set numericSort 1 + + if {$col == 1} { + set numericSort 0 + } + + set results "" + + foreach cache [ns_cache_names] { + set t [ns_cache_stats $cache] + + scan [ns_cache_size $cache] "%d %d" M N + scan $t "entries: %d flushed: %d hits: %d misses: %d hitrate: %d" e f h m p + + lappend results [list $cache $M $N $e $f $h $m "$p%"] + } + + set colTitles [list Cache Max Current Entries Flushes Hits Misses "Hit Rate"] + set rows [monitoring::sortResults $results [expr $col - 1] $numericSort $reverseSort] + + set html [monitoring::header Cache] + append html [monitoring::results $col $colTitles cache $rows $reverseSort] + append html [monitoring::footer] + + return $html +} + +proc monitoring::locks {} { + set col [ns_queryget col 1] + set reverseSort [ns_queryget reversesort 1] + + set numericSort 1 + set colTitles [list Name Owner ID Locks Busy Contention] + set rows "" + + if {$col == 1 || $col == 2} { + set numericSort 0 + } + + set results "" + + foreach l [ns_info locks] { + set name [lindex $l 0] + set owner [lindex $l 1] + set id [lindex $l 2] + set nlock [lindex $l 3] + set nbusy [lindex $l 4] + + if {$nbusy == 0} { + set contention 0.0 + } else { + set contention [expr double($nbusy*100.0/$nlock)] + } + + lappend results [list $name $owner $id $nlock $nbusy $contention] + } + + foreach result [monitoring::sortResults $results [expr $col - 1] $numericSort $reverseSort] { + set name [lindex $result 0] + set owner [lindex $result 1] + set id [lindex $result 2] + set nlock [lindex $result 3] + set nbusy [lindex $result 4] + set contention [lindex $result 5] + + if {$contention < 2} { + set color "black" + } elseif {$contention < 5} { + set color "orange" + } else { + set color "red" + } + + lappend rows [list "$name" "$owner" "$id" "$nlock" "$nbusy" "$contention"] + } + + set html [monitoring::header Locks] + + if {![ns_config -bool ns/threads mutexmeter 0]} { + set msg "\ + Mutex metering not enabled. To enable add the following to your server configuration: +
+ns_section ns/threads
+ns_param mutexmeter true
+
" + + append html [monitoring::msg warning $msg] + } + + append html [monitoring::results $col $colTitles locks $rows $reverseSort] + append html [monitoring::footer] + + return $html +} + +proc monitoring::log {} { + set log "" + + catch { + set f [open [ns_info log]] + seek $f 0 end + set n [expr [tell $f] -4000] + + if {$n < 0} { + set n 4000 + } + + seek $f $n + gets $f + set log [ns_quotehtml [read $f]] + close $f + } + + set html [monitoring::header Log] + append html "
$log
" + append html [monitoring::footer] + + return $html +} + +proc monitoring::mempools {} { + set talloc 0 + set trequest 0 + set tused 0 + set tlocks 0 + set twaits 0 + set tfree 0 + set tops 0 + + set html [monitoring::header Memory] + + append html "\ + + + + + + + +
" + + foreach p [lsort [ns_info pools]] { + append html "\ + [lindex $p 0]: +

+ + + + +
+ + + + + + + + + + + + " + + foreach b [lrange $p 1 end] { + set bs [lindex $b 0] + set nf [lindex $b 1] + set ng [lindex $b 2] + set np [lindex $b 3] + set nr [lindex $b 4] + set nu [expr $ng - $np] + set na [expr $nu * $bs] + + incr tops [expr $ng + $np] + incr tlocks [lindex $b 5] + incr twaits [lindex $b 6] + incr tfree [expr $bs * $nf] + incr talloc $na + incr trequest $nr + incr tused $nu + + if {$nr != 0} { + set ov [expr $na - $nr] + set op [format %4.2f%% [expr $ov.0 * 100 / $nr.0]] + } else { + set ov "N/A" + set op "N/A" + } + + append html "" + + foreach e [linsert [lreplace $b 4 4] 4 $nr $na $op] { + append html "" + } + + append html "" + } + + append html "\ +
Block SizeFreesGetsPutsBytes ReqBytes UsedOverheadLocksLock Waits
$e
+
+
" + } + + set ov [expr $talloc - $trequest] + set op [format %4.2f [expr $ov.0 * 100 / $trequest.0]] + set av [format %4.2f [expr 100.0 - ($tlocks.0 * 100) / $tops.0]] + + if {$tlocks > 0} { + set wr [format %4.2f [expr $twaits.0 / $tlocks.0]] + } else { + set wr N/A + } + + append html "\ +
+ Totals:

+ + + + + + + + + + + +
Bytes Requested:$trequest
Bytes Free:$tfree
Bytes Allocated:$talloc
Bytes Wasted:$ov
Byte Overhead:${op}%
Mutex Locks:$tlocks
Mutex Lock Waits:$twaits
Lock Wait Ratio:${wr}%
Gets/Puts:${tops}
Lock Avoidance:${av}%
+
" + + append html [monitoring::footer] + + return $html +} + +proc monitoring::process {} { + set values [list \ + Host "[ns_info hostname] ([ns_info address])" \ + "Boot Time" [clock format [ns_info boottime] -format %c] \ + Uptime [monitoring::fmtSeconds [ns_info uptime]] \ + Process "[ns_info pid] [ns_info nsd]" \ + Configuration [ns_info config] \ + "Page Root" [ns_info pageroot] \ + "Tcl Library" [ns_info tcllib] \ + Log [ns_info log] \ + Version "[ns_info version] ([ns_info label])" \ + "Build Date" [ns_info builddate] \ + Servers [join [ns_info servers]
] \ + Threads [join [ns_server threads]
] \ + "Keep Alive" [ns_server keepalive] \ + Callbacks [join [ns_info callbacks]
] \ + "Socket Callbacks" [join [ns_info sockcallbacks]
] \ + Active [join [ns_server active]
]] + + set html [monitoring::header Process] + + append html "\ + + + + +
+ + + + + " + + foreach {key value} $values { + append html "\ + + + + " + } + + append html "\ +
KeyValue
$key$value
+
" + + append html [monitoring::footer] + + return $html +} + +proc monitoring::sched {} { + set col [ns_queryget col 1] + set reverseSort [ns_queryget reversesort 1] + + set numericSort 1 + set scheduledProcs "" + + foreach s [ns_info scheduled] { + set id [lindex $s 0] + set flags [lindex $s 1] + set next [lindex $s 3] + set lastqueue [lindex $s 4] + set laststart [lindex $s 5] + set lastend [lindex $s 6] + set proc [lindex $s 7] + set arg [lindex $s 8] + + if [catch { + set duration [expr $lastend - $laststart] + }] { + set duration "0" + } + + set state "pending" + + if [monitoring::isThreadSuspended $flags] { + set state suspended + } + + if [monitoring::isThreadRunning $flags] { + set state running + } + + lappend scheduledProcs [list $id $state $proc $arg $flags $lastqueue $laststart $lastend $duration $next] + } + + set rows "" + + foreach s [monitoring::sortResults $scheduledProcs [expr $col - 1] $numericSort $reverseSort] { + set id [lindex $s 0] + set state [lindex $s 1] + set flags [join [monitoring::getSchedFlagTypes [lindex $s 4]] "
"] + set next [monitoring::fmtTime [lindex $s 9]] + set lastqueue [monitoring::fmtTime [lindex $s 5]] + set laststart [monitoring::fmtTime [lindex $s 6]] + set lastend [monitoring::fmtTime [lindex $s 7]] + set proc [lindex $s 2] + set arg [lindex $s 3] + set duration [monitoring::fmtSeconds [lindex $s 8]] + + lappend rows [list $id $state $proc $arg $flags $lastqueue $laststart $lastend $duration $next] + } + + set colTitles [list ID Status Callback Data Flags "Last Queue" "Last Start" "Last End" Duration "Next Run"] + + set html [monitoring::header "Scheduled Proceedures"] + append html [monitoring::results $col $colTitles sched $rows $reverseSort] + append html [monitoring::footer] + + return $html +} + +proc monitoring::threads {} { + set col [ns_queryget col 1] + set reverseSort [ns_queryget reversesort 1] + + set numericSort 1 + set colTitles [list Thread Parent ID Flags "Create Time" Proc Args] + set rows "" + + if {$col == 1 || $col == 2 || $col == 6 || $col == 7} { + set numericSort 0 + } + + set rows "" + + foreach t [monitoring::sortResults [ns_info threads] [expr $col - 1] $numericSort $reverseSort] { + set thread [lindex $t 0] + set parent [lindex $t 1] + set id [lindex $t 2] + set flags [monitoring::getThreadType [lindex $t 3]] + set create [monitoring::fmtTime [lindex $t 4]] + set proc [lindex $t 5] + set arg [lindex $t 6] + + if {[string match "p:0x0" $proc]} { + set proc "NULL" + } + + if {[string match "a:0x0" $arg]} { + set arg "NULL" + } + + lappend rows [list $thread $parent $id $flags $create $proc $arg] + } + + set html [monitoring::header Threads] + append html [monitoring::results $col $colTitles threads $rows $reverseSort] + append html [monitoring::footer] + + return $html +} + +proc monitoring::results {{selectedColNum ""} {colTitles ""} {colUrl ""} {rows ""} {reverseSort ""} {colAlignment ""}} { + set numCols [llength $colTitles] + + for {set colNum 1} {$colNum < [expr $numCols + 1]} {incr colNum} { + if {$colNum == $selectedColNum} { + set colHdrColor($colNum) "#666666" + set colHdrFontColor($colNum) "#ffffff" + set colColor($colNum) "#ececec" + } else { + set colHdrColor($colNum) "#999999" + set colHdrFontColor($colNum) "#ffffff" + set colColor($colNum) "#ffffff" + } + } + + set html "\ + + + + +
+ + " + + set i 1 + + foreach title $colTitles { + set url $colUrl + + if {$i == $selectedColNum} { + if $reverseSort { + append url "?reversesort=0" + } else { + append url "?reversesort=1" + } + } else { + append url "?reversesort=$reverseSort" + } + + set colAlign "left" + + if [llength $colAlignment] { + set align [lindex $colAlignment [expr $i - 1]] + + if [string length $align] { + set colAlign $align + } + } + + append html "" + + incr i + } + + append html "" + + foreach row $rows { + set i 1 + + append html "" + + foreach column $row { + set colAlign "left" + + if [llength $colAlignment] { + set align [lindex $colAlignment [expr $i - 1]] + + if [string length $align] { + set colAlign $align + } + } + + append html "" + + incr i + } + + append html "" + } + + append html "\ +
$title
$column
+
" + + return $html +} + +proc monitoring::msg {type msg} { + switch $type { + "error" { + set color "red" + } + "warning" { + set color "orange" + } + "success" { + set color "green" + } + default { + set color "black" + } + } + + return "[string toupper $type]:

$msg
" +} + +proc monitoring::getValue {key} { + if {![nsv_exists _ns_stats $key]} { + return "" + } + + return [nsv_get _ns_stats $key] +} + +proc monitoring::getThreadType {flag} { + return [monitoring::getValue thread_$flag] +} + +proc monitoring::getSchedType {flag} { + return [monitoring::getValue sched_$flag] +} + +proc monitoring::getSchedFlag {type} { + return [monitoring::getValue sched_$type] +} + +proc monitoring::isThreadSuspended {flags} { + return [expr $flags & [monitoring::getSchedFlag paused]] +} + +proc monitoring::isThreadRunning {flags} { + return [expr $flags & [monitoring::getSchedFlag running]] +} + +proc monitoring::getSchedFlagTypes {flags} { + if [expr $flags & [monitoring::getSchedFlag once]] { + set types "once" + } else { + set types "repeating" + } + + if [expr $flags & [monitoring::getSchedFlag daily]] { + lappend types "daily" + } + + if [expr $flags & [monitoring::getSchedFlag weekly]] { + lappend types "weekly" + } + + if [expr $flags & [monitoring::getSchedFlag thread]] { + lappend types "thread" + } + + return $types +} + +proc monitoring::fmtSeconds {seconds} { + if {$seconds < 60} { + return "${seconds} (s)" + } + + if {$seconds < 3600} { + set mins [expr $seconds/60] + set secs [expr $seconds - ($mins * 60)] + + return "${mins}:${secs} (m:s)" + } + + set hours [expr $seconds/3600] + set mins [expr ($seconds - ($hours * 3600))/60] + set secs [expr $seconds - (($hours * 3600) + ($mins * 60))] + + return "${hours}:${mins}:${secs} (h:m:s)" +} + +proc monitoring::fmtTime {time} { + if {$time < 0} { + return "never" + } + + return [clock format $time -format "%I:%M:%S %p on %m/%d/%Y"] +} + +proc monitoring::sortResults {results field numeric {reverse 0}} { + global _sortListTmp + + set _sortListTmp(field) $field + set _sortListTmp(numeric) $numeric + set _sortListTmp(reverse) $reverse + + return [lsort -command monitoring::cmpField $results] +} + +proc monitoring::cmpField {v1 v2} { + global _sortListTmp + + set v1 [lindex $v1 $_sortListTmp(field)] + set v2 [lindex $v2 $_sortListTmp(field)] + + if $_sortListTmp(numeric) { + if $_sortListTmp(reverse) { + set cmp [monitoring::cmpNumeric $v2 $v1] + } else { + set cmp [monitoring::cmpNumeric $v1 $v2] + } + } else { + if $_sortListTmp(reverse) { + set cmp [string compare $v2 $v1] + } else { + set cmp [string compare $v1 $v2] + } + } + + return $cmp +} + +proc monitoring::cmpNumeric {n1 n2} { + if {$n1 < $n2} { + return -1 + } elseif {$n1 > $n2} { + return 1 + } + + return 0 +} Index: openacs-4/packages/monitoring/www/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/index.adp,v diff -u -r1.2 -r1.3 --- openacs-4/packages/monitoring/www/index.adp 20 Apr 2004 21:13:47 -0000 1.2 +++ openacs-4/packages/monitoring/www/index.adp 28 Aug 2007 12:59:28 -0000 1.3 @@ -14,6 +14,7 @@
  • Startup Log
  • Statistics from top
  • Table analysis +
  • System statistics @dev_support_link;noquote@ Index: openacs-4/packages/monitoring/www/nsstats/adp.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/adp.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/adp.adp 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1,2 @@ + +@html;noquote@ Index: openacs-4/packages/monitoring/www/nsstats/adp.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/adp.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/adp.tcl 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1 @@ +set html [monitoring::adp] Index: openacs-4/packages/monitoring/www/nsstats/cache.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/cache.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/cache.adp 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1,2 @@ + +@html;noquote@ Index: openacs-4/packages/monitoring/www/nsstats/cache.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/cache.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/cache.tcl 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1 @@ +set html [monitoring::cache] Index: openacs-4/packages/monitoring/www/nsstats/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/index.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/index.adp 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1,12 @@ + + + Index: openacs-4/packages/monitoring/www/nsstats/locks.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/locks.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/locks.adp 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1,2 @@ + +@html;noquote@ Index: openacs-4/packages/monitoring/www/nsstats/locks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/locks.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/locks.tcl 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1 @@ +set html [monitoring::locks] Index: openacs-4/packages/monitoring/www/nsstats/log.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/log.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/log.adp 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1,2 @@ + +@html;noquote@ Index: openacs-4/packages/monitoring/www/nsstats/log.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/log.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/log.tcl 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1 @@ +set html [monitoring::log] Index: openacs-4/packages/monitoring/www/nsstats/mempools.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/mempools.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/mempools.adp 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1,2 @@ + +@html;noquote@ Index: openacs-4/packages/monitoring/www/nsstats/mempools.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/mempools.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/mempools.tcl 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1 @@ +set html [monitoring::mempools] Index: openacs-4/packages/monitoring/www/nsstats/process.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/process.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/process.adp 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1,2 @@ + +@html;noquote@ Index: openacs-4/packages/monitoring/www/nsstats/process.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/process.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/process.tcl 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1 @@ +set html [monitoring::process] Index: openacs-4/packages/monitoring/www/nsstats/sched.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/sched.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/sched.adp 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1,2 @@ + +@html;noquote@ Index: openacs-4/packages/monitoring/www/nsstats/sched.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/sched.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/sched.tcl 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1 @@ +set html [monitoring::sched] Index: openacs-4/packages/monitoring/www/nsstats/threads.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/threads.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/threads.adp 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1,2 @@ + +@html;noquote@ Index: openacs-4/packages/monitoring/www/nsstats/threads.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/nsstats/threads.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/monitoring/www/nsstats/threads.tcl 28 Aug 2007 12:59:29 -0000 1.1 @@ -0,0 +1 @@ +set html [monitoring::threads]