---
title: Reconfiguring Your Site Based on Traffic Load
slug: ps/help/en_us/vtm/controlapi/reconfiguring-your-site-based-on-traffic-load
docTags: 
createdAt: 2026-08-02T08:52:21.053Z
---

This code example monitors the performance of the JSP pages on a Web site. If the performance drops below an acceptable level, the example uses the Control API to enable a TrafficScript rule that prevents more users from logging in to the Web site. After performance climbs back to an acceptable level, the Control API application can disable the rule.

### The TrafficScript Rule

To prevent users from logging in to the Web site, use a TrafficScript rule similar to the following:

```bash
$path = http.getPath();
if( string.endsWith( $path, "login.jsp" ) ) {
http.redirect( "/content/login_disabled.html" );
}
```

Add this rule to the Rules catalog and name it “Disable Login” (referenced later). Configure it as a request rule for your Virtual Server, but set it to be disabled. The Control API application uses the Virtual Server getRules() and setRules() functions to modify the “enabled” status of the rule.

### Monitoring Performance

Performance of the Web application can be monitored in a variety of ways:

- Using statistics gathered from the Web application itself.
- Using an external monitoring tool to send probe requests.
- Monitoring the node response times using SNMP and the Service Level Monitoring capability.
- Using the SNMP or email alerts raised by Service Level Monitoring to drive the Control API applications directly.

### Enabling and Disabling the Rule

The following Control API code retrieves the list of response rules that the named virtual server is using. It searches for the rule named “Disable Login” and enables it. If the rule is not present, it adds it as the first rule to be executed.

### Perl Example

```bash
#!/usr/bin/perl -w

use SOAP::Lite 0.60;

# Provide our own Deserializer so to deserialize enums correctly
BEGIN {
package MyDeserializer;
@MyDeserializer::ISA = 'SOAP::Deserializer';

sub typecast {
my( $self, $val, $name, $attrs, $children, $type ) = @_;
if( $type && $type =~ m@http://soap.zeus.com/zxtm/@) {
return $val;
}
return undef;
};
}

# This is the url of the Traffic Manager Admin Server
my $admin_server = 'https://username:password@host:9090';

# The virtual server to edit, and the rule to enable
my $vsName = "Main web site";
my $rule = "Disable Login";

my $conn = SOAP::Lite
-> uri('http://soap.zeus.com/zxtm/1.0/VirtualServer/')
-> proxy("$admin_server/soap")
-> deserializer( MyDeserializer->new )
-> on_fault( sub {
my( $conn, $res ) = @_;
die ref $res ? $res->faultstring:conn->transport->status; } );

# Get a list of rules used by the named virtual server
my $res = $conn->getRules( [ $vsName ] );
my @rules = @{${$res->result}[0]};

my $found = 0;
foreach my $f ( @rules ) {
if( $f->{name} eq $rule ) {
$f->{enabled} = 1; $found = 1; last;
}
}
if( !$found ) {
# Add a new rule to the start of the list
unshift @rules, {
name => $rule,
enabled => 1,
run_frequency => 'only_first'
};
}

$res = $conn->setRules( [ $vsName ], [ [ @rules ] ] );
```

### Notes

The rule’s manipulation functions take a compound VirtualServer.Rule structure which uses an enumeration named “RuleRunFlag”.

The SOAP\::Lite interface presents this structure as a standard Perl hash, requiring a deserializer to manage the enumeration.

C# presents it as an object of type VirtualServerRule containing an enumeration of type VirtualServerRuleRunFlag.

### C# Example

```bash
using System;
using System.Net;
using System.IO;
using System.Security.Cryptography.X509Certificates;

public class AllowSelfSignedCerts : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint sp, X509Certificate cert,
WebRequest request, int problem )
{
return true;
}
}

public class addNode {
public static void Main( string [] args )
{
System.Net.ServicePointManager.CertificatePolicy =
new AllowSelfSignedCerts();

string url= "https://host:9090/soap";
string username = "username";
string password = "password";

string vsName = "Main web site";
string rule = "Disable login";
try {
         VirtualServer p = new VirtualServer();
p.Url = url;
p.Credentials = new NetworkCredential(
username, password );

// Get a list of rules used by the named
// virtual server
         VirtualServerRule[][] rules =
p.getRules( new string[] { vsName } );

// Search for the rule to enable
bool found = false;
foreach( VirtualServerRule r in rules[0] ) {
if( r.name == rule ) {
found = true; r.enabled = true;
}
}
if( ! found ) {
// Add a new rule to the start of the list
            VirtualServerRule[] newrules = new
               VirtualServerRule[rules[0].Length + 1];
newrules[0] = new VirtualServerRule();
newrules[0].name = rule;
newrules[0].enabled = true;
newrules[0].run_frequency =
               VirtualServerRuleRunFlag.only_first;

Array.Copy( rules[0], 0, newrules, 1, rules[0].Length );

rules[0] = newrules;
}
p.setRules( new string[] { vsName }, rules );

} catch ( Exception e ) {
Console.WriteLine( "{0}", e );
}
}
}
```
