cancel
Showing results for 
Search instead for 
Did you mean: 

Instrument web content with Stingray Traffic Manager

This simple TrafficScript rule helps you debug and instrument the traffic manager.  It adds a simple overlay on each web page containing key information that is useful in a test and debugging situation:

 

basicinfo.png

 

  • Served from: identifies the server node that generated the response
  • Took XX seconds: using the technique in HowTo: Log slow connections in Stingray Traffic Manager identifies the time between recieving the HTTP request and completion of response rules
  • Took YY retries: if present, indicates that the traffic manager had to retry the request one or more times before getting a satisfactory response

 

The TrafficScript response rule is as follows:

 

$ct = http.getResponseHeader( "Content-Type" );  
if( !string.startsWith( $ct, "text/html" ) ) break;  
  
$style = '  
<style type="text/css">  
.stingrayTip {  
   position:absolute;  
   top:0;  
   right:0;  
   background:black;  
   color:#acdcac;  
   opacity:.6;  
   z-index:100;  
   padding:4px;  
}  
.stingrayTip:hover {  
   opacity:.8;  
}  
</style>';  
  
$text = "Served from " . connection.getNode();  
if( request.getRetries() ) $text .= "<br>Took " . request.getRetries() . " retries";  
if( connection.data.get("start") ) $text .= "<br>Took " . (sys.time.highres()-connection.data.get("start")) . " seconds";  
if( connection.data.get("notes") ) $text .= "<br>" . connection.data.get( "notes" );  
  
$body = http.getResponseBody();  
  
$html = '<div class="stingrayTip">' . $text . '</div>';  
$body = string.regexsub( $body, "(<body[^>]*>)", $style."$1\n".$html."\n", "i" );  
http.setResponseBody( $body );  

 

Using the timing information

 

To get the 'took XX seconds' information, place the rule as late as possible in your chain of response rules, and add the following rule as a request rule, to run as early as possible:

 

    $tm = sys.time.highres();  
    connection.data.set("start", string.sprintf( "%f", $tm ) ); 

 

See HowTo: Log slow connections in Stingray Traffic Manager for more information.

 

Additional information

 

You can present additional information in the info box by storing it in a connection-local variable called 'notes', for example:

 

$cookies = http.getHeader( "Cookie" );  
$msg = "Cookies: " . $cookies;  
connection.data.set( 'notes', $msg );  

 

Read more

 

This example uses techniques similar to the Watermarking web content with Stingray and TrafficScript article.

Version history
Revision #:
1 of 1
Last update:
‎03-20-2013 07:10:AM
Updated by:
 
Labels (1)