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.7 -r1.8 --- openacs-4/packages/xotcl-request-monitor/xotcl-request-monitor.info 4 Oct 2008 19:26:51 -0000 1.7 +++ openacs-4/packages/xotcl-request-monitor/xotcl-request-monitor.info 21 Sep 2011 08:05:06 -0000 1.8 @@ -8,7 +8,7 @@ t request-monitor - + Gustaf Neumann Request Monitor with user tracking functionality 2008-10-04 @@ -19,8 +19,8 @@ 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.5 -r1.6 --- openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-init.tcl 23 May 2008 19:23:23 -0000 1.5 +++ openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-init.tcl 21 Sep 2011 08:05:06 -0000 1.6 @@ -1,7 +1,7 @@ # we register the following filters only during startup, since # existing connection threads are not aware of the throttle object. -if {[ns_server connections]==0} { +if {[ns_server connections] == 0 && [info command ::throttle] ne ""} { # # Register the filter progs for url statistics. # The methods to be called have the name of the filter type. 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.37 -r1.38 --- openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-procs.tcl 10 Feb 2011 16:37:22 -0000 1.37 +++ openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-procs.tcl 21 Sep 2011 08:05:06 -0000 1.38 @@ -1,4 +1,11 @@ ############################################################################# +# Main procs of Request Monitor +# +# Create a separate thread (named "throttle") to act as a monitor of +# the incoming requests. The monitor blocks repeated requests, +# throttles over-eager users and provides a wide set of statistics. +############################################################################# + ::xotcl::THREAD create throttle { # @@ -55,6 +62,27 @@ if {![file isdirectory $logdir]} {file mkdir $logdir} # + # Create AsyncLogFile class, which is one client of the + # AsyncDiskWriter from bgdelivery + # + Class create AsyncLogFile -parameter {filename {mode a}} + AsyncLogFile instproc init {} { + if {![my exists filename]} { + my filename $::logdir/[namespace tail [self]] + } + my set handle [bgdelivery do AsyncDiskWriter new -autoflush true] + bgdelivery do [my set handle] open -filename [my filename] -mode [my mode] + } + AsyncLogFile instproc write {msg} { + bgdelivery do [my set handle] async_write $msg\n + } + + # open the used log-files + AsyncLogFile create counter.log + AsyncLogFile create long-calls.log + AsyncLogFile create switches.log + + # # A class to keep simple statistics # Class create ThrottleStat -parameter { type requestor timestamp ip_adress url } @@ -272,14 +300,13 @@ } #throttle do throttler mixin ThrottleTrace + # yyyy Class create TraceLongCalls TraceLongCalls set count 0 TraceLongCalls instproc log {msg} { - set traceFile [open $::logdir/long-calls.log a] - puts $traceFile "[clock format [clock seconds]] -- $msg" - close $traceFile + long-calls.log write "[clock format [clock seconds]] -- $msg" [self class] append log "[clock format [clock seconds]] -- $msg\n" [self class] incr count } @@ -340,11 +367,10 @@ my c 0 } + Counter instproc log_to_file {timestamp label value} { set server [ns_info server] - set f [open $::logdir/counter.log a] - puts $f "$timestamp -- $server $label $value" - close $f + counter.log write "$timestamp -- $server $label $value" } Counter instproc add_value {timestamp n} { @@ -705,10 +731,8 @@ } # log the change set timestamp [clock format [clock seconds]] - set f [open $::logdir/switches.log a] - puts $f "$timestamp -- switch $key from\ + switches.log write "$timestamp -- switch $key from\ [$class set pa($key)] to $pa $url" - close $f } } set counter active($key) @@ -904,8 +928,7 @@ Users time_window_cleanup Users compute_nr_users_per_day } - dump proc write {} { - set dumpFile [open [my set file] w] + dump proc write {{-sync false}} { set cmd "" # dump all variables of the object ::Users set o ::Users @@ -919,8 +942,16 @@ append cmd [list $o set $var [$o set $var]] \n } } - puts $dumpFile $cmd - close $dumpFile + if {$sync} { + set dumpFile [open [my set file] w] + puts -nonewline $dumpFile $cmd + close $dumpFile + } else { + set dumpFile [bgdelivery do AsyncDiskWriter new] + bgdelivery do $dumpFile open -filename [my set file] + bgdelivery do $dumpFile async_write $cmd + bgdelivery do $dumpFile close + } } # initialization of Users class object @@ -994,7 +1025,7 @@ # down. # ::xotcl::Object setExitHandler { - dump write + dump write -sync true } 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.18 -r1.19 --- openacs-4/packages/xotcl-request-monitor/www/index.tcl 10 Feb 2011 16:37:22 -0000 1.18 +++ openacs-4/packages/xotcl-request-monitor/www/index.tcl 21 Sep 2011 08:05:06 -0000 1.19 @@ -87,7 +87,7 @@ proc currentViews {} { set vm [throttle trend minutes] set um [throttle trend user_count_minutes] - if { $vm eq "" } { return "NO DATA" } + if { $vm eq "" || $um eq ""} { return "NO DATA" } set views_per_sec [expr {[lindex $vm end]/60.0}] #ns_log notice "um='$um' vm='$vm' expr {60.0*$views_per_sec/[lindex $um end]}" set views_per_min_per_user [expr {60.0*$views_per_sec/[lindex $um end]}]