Contribute Open Script

HTTP status code counter

by kobayash on ‎07-13-2012 12:43 AM (82 Views)

Tested with Brocade ServerIron ADX : Yes

Description :

Collect HTTP status code and displayed if special query found.  This script collects status code with SLB without special query.  If administrator would like to check statistics, he/she use special query.  In this script, just use "stat=stat".  With above query, the script returns statistics what they count.

Limitations :

The counters resets under such conditions, unbind VIP, reload, etc.  Also the counters are volatile.

Required environment  :

Assume the group id of server pool is 10.

Comments :

That is trivial sample, OpenScript has several capabilities such as hashing.

Source Code

use OS_HTTP_REQUEST;
use OS_HTTP_RESPONSE;
use OS_SLB;

#Count each status code for HTTP response.
#This script collect status code with SLB without special quesry.
#If administrator would like to check statistics, he/she use speial query.
#In this script, just use "stat=stat"
#With above query, the script returns statistics what they count.

#Init hash
#You may add addtional counters such as 302, etc.

BEGIN {
$cnt_req=0;
$group=10;
%code;
$code{"200"}=0;
$code{"404"}=0;
}

sub HTTP_REQUEST{
        $query_val=OS_HTTP_REQUEST::query;
#        print $query_val."\r\n";
        if($query_val eq "stat=stat"){
        my $err_code = "HTTP/1.1 200 Answered by OpenScript\r\nServer: Brocade OpenScript (Brocade)\r\nContent-Length: 160\r\nKeep-Alive: timeout=15, max=100\r\nConnection: Close\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n<html><head>\n</head><title>Stats for this Virtual Server </title>\n</head><body>Total requests are $cnt_req<BR>Total 200 are $code{'200'}<BR>Total 404 are $code{'404'}<BR></body></html>";
        OS_SLB::reply($err_code);
        }else{
        $cnt_req++;
        OS_SLB::forward($group);
        }
}


#Just collect HTTP status code.

sub HTTP_RESPONSE{
        my $code = OS_HTTP_RESPONSE::code;
        if ($code eq "200"){
        $code{"200"}++;
        }elsif($code eq "404"){
        $code{"404"}++;
        }
}

Comments
by Derek_Kang on ‎07-23-2012 03:48 PM

I find this contribution very creative, opening up other possibilities to provide visibility into application delivery infrastructure!

by kobayash on ‎07-23-2012 11:18 PM

Thanks Derek,

The openscript(perl) has several capabilities, I will post some tribial samples in near future.

I appriacite if the openscript can open some text file which includes match and repleace rules.

It will be slightly hard, but it can provide clear perspective such as url_rewrite, etc.