vADC Docs

Instrument web content with Stingray Traffic Manager

by on ‎03-20-2013 07:10 AM - edited on ‎06-01-2015 03:34 PM by PaulWallace (1,175 Views)

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.

Contributors