Contribute Open Script

[BRCD_OS_119] Request Redirect

by Yasir_Liaqatullah on ‎01-20-2012 03:25 PM (557 Views)

Area

Connections

Traffic

HTTP

Description

            This script tracks the connections to the service port on real-server and sends a redirect to client if these connections exceed a pre-defined threshold. If the threshold is not exceeded, the client request is forwarded to the real server.

Performance Estimate

            Contact us for our detailed reporting

               or

            Report your own performance estimate

Required Backend configuration

            No special configuration is required

Events and API Used

Events

API

HTTP_REQUEST

OS_SLB::get_server_port_current_connection

OS_SLB::redirect

OS_SLB::forward

Script source code

# Purpose: Redirect incoming Requests if Current Connections on real server exceed a threshold

use OS_SLB;

use OS_HTTP_REQUEST;

sub BEGIN {

       # Change below variables to the name of server that should be monitored and the threshold value

       $server_name = "rs1";

       $server_port = 80;

       $connection_threshold = 10;

}

#############################################

#

# HTTP REQUEST EVENTS

#

#############################################

sub HTTP_REQUEST {

       # Get the current connections from the server

       $server_connections = OS_SLB::get_server_port_current_connections("$server_name", "$server_port");

       #print "Curent Connections to server are - $server_connections\n";

       if ($server_connections >= $connection_threshold) {

              #print "Connections exceeded Threshold of $connection_threshold. Sending Redirect to Client\n";

              OS_SLB::redirect("domain" => "www.somedomain.com", "status-code" => "302", "url" => "/newpage.html", "port" => "8980");

       } else {

              #print "Connections to server below threshold. Forwarding the request to the server\n";

              $server_id = OS_SLB::server_id("$server_name");

              OS_SLB::forward("$server_id");

       }

}