Forum Discussion

Yoda_34023's avatar
Yoda_34023
Icon for Nimbostratus rankNimbostratus
Jun 15, 2007

Monitoring end-to-end repsonse time

Hi,

 

 

Have a nice little problem. I would like to do the following:

 

 

1. Log all HTTP error codes so we can see what errors are happening, and ideally log what the clients where trying to access.

 

2. Measure response times from the client to the Server so we can see how long a total request/response took.

 

 

Now heres the problem (at least one of them) I want to allow a manager of the partition to view these results. I've had a look and from what I can see a manager does not have access to the syslog via the GUI. (v9.4.x code b.t.w)

 

 

 

Now heres a irule which I got from a previous topic which sort of helps I think, but suspect it can be made alot more slicker.

 

 

This does not address point 2 though.
when RULE_INIT {
   store the profile name in a variable for easy modification later.
  set :ROFILE_NAME "user_experience"
}
when HTTP_REQUEST {
   store the number of milliseconds since the epoch (you'll find out why later)
  set t0 [clock clicks -milliseconds]
   add some secret control functions to manipulate the statistics
  switch [string tolower [HTTP::uri]] {
    "/getuserstats" {
       Avoid divide by zero errors
      set time_per_req 0
      set total_time [STATS::get $:ROFILE_NAME total_time]
      set num_requests [STATS::get $:ROFILE_NAME num_requests]
      if { $num_requests > 0 } {
        set time_per_req [expr $total_time / $num_requests]
      }
       Hand roll a HTTP response to serve up the statistics report
      HTTP::respond 200 content "
        HTTP Status Code Report
        
        
                HTTP
Status CodeResponse
Count        203[STATS::get $:ROFILE_NAME 203]        204[STATS::get $:ROFILE_NAME 204]        205[STATS::get $:ROFILE_NAME 205]        206[STATS::get $:ROFILE_NAME 206]        400[STATS::get $:ROFILE_NAME 400]        401[STATS::get $:ROFILE_NAME 401]        403[STATS::get $:ROFILE_NAME 403]        404[STATS::get $:ROFILE_NAME 404]        405[STATS::get $:ROFILE_NAME 405]        406[STATS::get $:ROFILE_NAME 406]        408[STATS::get $:ROFILE_NAME 408]        409[STATS::get $:ROFILE_NAME 409]        500[STATS::get $:ROFILE_NAME 500]        501[STATS::get $:ROFILE_NAME 501]        502[STATS::get $:ROFILE_NAME 502]        503[STATS::get $:ROFILE_NAME 503]        504[STATS::get $:ROFILE_NAME 504]        505[STATS::get $:ROFILE_NAME 505]        507[STATS::get $:ROFILE_NAME 507]        509[STATS::get $:ROFILE_NAME 509]        Num Requests[STATS::get $:ROFILE_NAME num_requests]        Total Time[STATS::get $:ROFILE_NAME total_time] ms.        Avg Time/Req$time_per_req ms.        "
    }
    "/resetuserstats" {
       Reset all the statistics values to zero
      STATS::set $:ROFILE_NAME "203" 0
      STATS::set $:ROFILE_NAME "204" 0
      STATS::set $:ROFILE_NAME "205" 0
      STATS::set $:ROFILE_NAME "206" 0
      STATS::set $:ROFILE_NAME "401" 0
      STATS::set $:ROFILE_NAME "403" 0
      STATS::set $:ROFILE_NAME "404" 0
      STATS::set $:ROFILE_NAME "405" 0
      STATS::set $:ROFILE_NAME "406" 0
      STATS::set $:ROFILE_NAME "408" 0
      STATS::set $:ROFILE_NAME "409" 0
      STATS::set $:ROFILE_NAME "500" 0
      STATS::set $:ROFILE_NAME "501" 0
      STATS::set $:ROFILE_NAME "502" 0
      STATS::set $:ROFILE_NAME "503" 0
      STATS::set $:ROFILE_NAME "504" 0
      STATS::set $:ROFILE_NAME "505" 0
      STATS::set $:ROFILE_NAME "507" 0
      STATS::set $:ROFILE_NAME "509" 0
      STATS::set $:ROFILE_NAME "num_requests" 0
      STATS::set $:ROFILE_NAME "total_time" 0
       Hand roll a HTTP response indicating reset status
      HTTP::respond 200 content "
        HTTP Status Code Control
        Statistics Successfully reset
        "
    }
  }
}
when HTTP_RESPONSE {
   use the clock command to get the delta in milliseconds between
   the request and the response.  This doesn't give the true
   time the client waits, but it is pretty close to the server
   processing time.
  set t1 [clock clicks -milliseconds]
  set total_time [expr $t1 - $t0]
   Increment the statistics profile values
  switch -glob [HTTP::status] {
    "20*" {
      STATS::incr $:ROFILE_NAME "203" 1
      STATS::incr $:ROFILE_NAME "204" 1
      STATS::incr $:ROFILE_NAME "205" 1
      STATS::incr $:ROFILE_NAME "206" 1
    }
    "40*" {
      STATS::incr $:ROFILE_NAME "401" 1
      STATS::incr $:ROFILE_NAME "403" 1
      STATS::incr $:ROFILE_NAME "404" 1
      STATS::incr $:ROFILE_NAME "405" 1
      STATS::incr $:ROFILE_NAME "406" 1
      STATS::incr $:ROFILE_NAME "408" 1
      STATS::incr $:ROFILE_NAME "409" 1
    }
    "50*" {
      STATS::incr $:ROFILE_NAME "500" 1
      STATS::incr $:ROFILE_NAME "501" 1
      STATS::incr $:ROFILE_NAME "502" 1
      STATS::incr $:ROFILE_NAME "503" 1
      STATS::incr $:ROFILE_NAME "504" 1
      STATS::incr $:ROFILE_NAME "507" 1
      STATS::incr $:ROFILE_NAME "509" 1
    }
  }
  STATS::incr $:ROFILE_NAME "num_requests" 1
  STATS::incr $:ROFILE_NAME "total_time" $total_time
}
No RepliesBe the first to reply