Index: openacs-4/packages/xotcl-request-monitor/xotcl-request-monitor.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-request-monitor/xotcl-request-monitor.info,v diff -u -r1.5 -r1.6 --- openacs-4/packages/xotcl-request-monitor/xotcl-request-monitor.info 14 Oct 2007 16:39:41 -0000 1.5 +++ openacs-4/packages/xotcl-request-monitor/xotcl-request-monitor.info 23 May 2008 19:23:23 -0000 1.6 @@ -8,23 +8,24 @@ t request-monitor - + Gustaf Neumann Request Monitor with user tracking functionality - 2007-10-14 + 2008-05-23 This package provides a Request Monitor for OACS applications. It computes performance summary information such as requests/views per seconds, average response time, number of users connected, lists currently active threads, etc. Furthermore it can block overactive users (e.g. automated web-bots mirroring the site, users repeating running queries, etc.). It provides as well some user tracking (such as whos-online) with activity measures, it blocks repeated requests (impatient reloads), tracks switching of IP-adresses from users and provides request tracking per user for the monitored time window. It contains as well overall url statistics with performance measures. Updated for cirumventing handler calls openacs 5.2 for /resources/*. 0.28 provides calles for listing active communities and users active in these communities. 0.30 provides a nice graphical chats (many thanks to Nima) and a new interface to the background thread. In addition, ns_returnfile_background is included; 0.38 using context form xotcl-core 0.39 brings parameterized counter values 0 - + + Index: openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-init.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-init.tcl 16 Sep 2007 11:15:15 -0000 1.4 +++ openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-init.tcl 23 May 2008 19:23:23 -0000 1.5 @@ -8,7 +8,7 @@ # ns_register_filter trace GET * throttle ns_register_filter trace POST * throttle - + #ns_register_filter postauth GET * throttle #ns_register_filter postauth POST * throttle ad_register_filter -priority 1000 postauth GET * throttle Index: openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-procs.tcl,v diff -u -r1.13 -r1.14 --- openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-procs.tcl 14 Oct 2007 16:39:41 -0000 1.13 +++ openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-procs.tcl 23 May 2008 19:23:23 -0000 1.14 @@ -27,7 +27,7 @@ package_parameter time-window -default 13 package_parameter trend-elements -default 48 package_parameter max-stats-elements -default 5 - package_parameter request-blocking-off -default 0 + package_parameter do_throttle -default on # # When updates happen on @@ -44,11 +44,11 @@ next Counter set_in_all_instances nr_trend_elements $value } - - request-blocking-off proc update {value} { + do_throttle proc update {value} { + next throttler set off $value } - + # get the value from the logdir parameter set ::logdir [log-dir] if {![file isdirectory $logdir]} {file mkdir $logdir} @@ -70,7 +70,7 @@ } Throttle instproc init {} { - my set off [request-blocking-off] + my set off [do_throttle] Object create [self]::stats Object create [self]::users next @@ -203,16 +203,44 @@ return [my array get active] } - Throttle instproc add_url_stat {url time_used key pa} { + Throttle instproc add_url_stat {url time_used key pa content_type} { catch {my unset running_url($key,$url)} #my log "### unset running_url($key,$url) $errmsg" - response_time_minutes add_url_stat $url $time_used $key + if {[string match text/html* $content_type]} { + [Users current_object] add_view $key + } + response_time_minutes add_url_stat $url $time_used $key $content_type } Throttle instforward report_url_stats response_time_minutes %proc Throttle instforward flush_url_stats response_time_minutes %proc Throttle instforward last100 response_time_minutes %proc Throttle create throttler + + Class create ThrottleTrace + ThrottleTrace instproc log {msg} { + if {![my exists traceFile]} { + set file $::logdir/calls + my set traceFile [open $file w] + my set traceCounter 0 + } + puts [my set traceFile] $msg + } + ThrottleTrace instproc throttle_check args { + catch { + if {[my exists traceCounter]} {my incr traceCounter} {my set traceCounter 0} + my incr traceCounter + my log "CALL [my set traceCounter] [self args]" + } + next + } + ThrottleTrace instproc add_url_stat args { + catch {my log "END [my set traceCounter] [self args]"} + next + } + + #throttle do throttler mixin ThrottleTrace + ############################ # A simple counter class, which is able to aggregate values in some # higher level counters (report_to) and to keep statistics in form @@ -630,6 +658,31 @@ } } + Users instproc add_view {uid} { + #my log "#### add_view $uid" + set key views($uid) + if {[my exists $key]} { + my incr $key + } else { + my set $key 1 + } + } + Users proc views_per_minute {uid} { + set mins 0 + set views 0 + set key views($uid) + foreach i [Users info instances] { + if {[$i exists $key]} { + incr mins + incr views [$i set $key] + } + } + if {$mins > 0} { + return [expr {$views*1.0/$mins}] + } + return 0 + } + Users instproc destroy {} { foreach key [my array names active] { [self class] decrRefCount $key [my set active($key)] @@ -719,6 +772,29 @@ } # + # define a class value, which refreshes itself all "refresh" ms. + # + Class Value -parameter {{value ""} {refresh 10000}} + Value instproc updateValue {} {my set handle [after [my refresh] [list [self] updateValue]]} + + # + # define a object loadAvg. + # + # query with: "throttle do loadAvg value" + # + Value create loadAvg + loadAvg proc updateValue {} { + set procloadavg /proc/loadavg + if {[file readable $procloadavg]} { + set f [open $procloadavg]; + my value [lrange [read $f] 0 2]; + close $f + } + next + } + loadAvg updateValue + + # # Populate the counters from log file # ns_log notice "+++ request-monitor: initialize counters" @@ -860,6 +936,7 @@ throttle forward max_values %self do %1 set stats throttle forward purge_access_stats %self do Users %proc throttle forward users %self do Users +throttle forward views_per_minute %self do Users %proc #### # the next procs are for the filters (registered from the -init file) @@ -892,7 +969,9 @@ # in these cases pre- or postauth are not called, but only trace. # So we have to make sure we have the needed context here my get_context - my add_url_stat [my set url] [my ms] [my set requestor] [my set pa] + #my log "CT=[ns_set array [ns_conn outputheaders]] -- [my set url]" + my add_url_stat [my set url] [my ms] [my set requestor] [my set pa] \ + [ns_set get [ns_conn outputheaders] Content-Type] my unset context_initialized return filter_ok } @@ -911,9 +990,9 @@ } { set string [string trim $string] if {[string length $string]>$len} { - set half [expr {($len-2)/2}] + set half [expr {($len-2)/2}] set left [string trimright [string range $string 0 $half]] - set right [string trimleft [string range $string end-$half end]] + set right [string trimleft [string range $string end-$half end]] return $left$ellipsis$right } return $string Index: openacs-4/packages/xotcl-request-monitor/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-request-monitor/www/index.tcl,v diff -u -r1.11 -r1.12 --- openacs-4/packages/xotcl-request-monitor/www/index.tcl 18 Sep 2007 10:21:45 -0000 1.11 +++ openacs-4/packages/xotcl-request-monitor/www/index.tcl 23 May 2008 19:23:24 -0000 1.12 @@ -34,10 +34,15 @@ # collect current system statistics proc currentSystemLoad {} { -# if {[catch {return [exec "/usr/bin/uptime"]}]} { -# return "" -# } -return [exec "/usr/bin/uptime"] + # if {[catch {return [exec "/usr/bin/uptime"]}]} { + # return "" + # } + set procloadavg /proc/loadavg + if {[file readable $procloadavg]} { + set f [open $procloadavg]; set c [read $f]; close $f + return $c + } + return [exec "/usr/bin/uptime"] } # collect current response time (per minute and hour) Index: openacs-4/packages/xotcl-request-monitor/www/whos-online.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-request-monitor/www/whos-online.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/xotcl-request-monitor/www/whos-online.tcl 26 Mar 2007 07:44:34 -0000 1.6 +++ openacs-4/packages/xotcl-request-monitor/www/whos-online.tcl 23 May 2008 19:23:24 -0000 1.7 @@ -43,6 +43,7 @@ Field activity -label "Activity" -html { align right } -orderby activity AnchorField hits -label "Hits" -orderby hits Field switches -label "Switches" -html { align center } -orderby switches + Field vpm -label "Views per min" -html { align center } -orderby vpm Field peer_address -label "Peer" -orderby peer_address } }] \ @@ -101,7 +102,9 @@ [format %.2f [lindex $smooth 0]] \ $hits $loadparam $detail_url \ $switches \ - $peer] + $peer \ + $user_id \ + ] } switch -glob $orderby { @@ -140,6 +143,7 @@ -hits [lindex $e 6] \ -hits.href [lindex $e 7] \ -switches [lindex $e 8] \ + -vpm [throttle views_per_minute [lindex $e 10]] \ -peer_address [lindex $e 9] } else { t1 add -name [lindex $e 0] \