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:
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 );
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.
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 );
This example uses techniques similar to the Watermarking web content with Stingray and TrafficScript article.