crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs

client (1119B)


      1 #!/usr/bin/perl
      2 
      3 use strict;
      4 use Socket;
      5 
      6 if ($#ARGV != 2) {
      7     die <<"ENDUSAGE";
      8 
      9 Usage: client ntimes host port
     10 
     11 ENDUSAGE
     12 }
     13 
     14 my ($ntimes, $host, $port) = @ARGV;
     15 
     16 print ("Starting client loop to query $host:$port..\n");
     17 select (undef, undef, undef, 0.2);
     18 
     19 my %hits = (a => 0, b => 0, c => 0, unknown => 0, errors => 0);
     20 
     21 for my $n (1..$ntimes) {
     22     open (my $if, "wget -vSO- http://$host:$port 2>&1 |")
     23       or die ("Can't start wget: $!\n");
     24     my ($a, $b, $c, $unk, $err);
     25     $err = 1;
     26     while (my $msg = <$if>) {
     27 	chomp ($msg);
     28         # print ("Server says: [$msg]\n");
     29 	if ($msg =~ /HTTP.*200 OK/ or $msg =~ /Hello World/) {
     30 	    $err = 0;
     31 	} elsif ($msg =~ /Backend_A/) {
     32 	    $a = 1;
     33 	} elsif ($msg =~ /Backend_B/) {
     34 	    $b = 1;
     35 	} elsif ($msg =~ /Backend_C/) {
     36 	    $c = 1;
     37 	}
     38     }
     39     close ($if);
     40 
     41     $unk = 1 if ($a == 0 and $b == 0 and $c == 0);
     42 
     43     $hits{a} += $a;
     44     $hits{b} += $b;
     45     $hits{c} += $c;
     46     $hits{unknown} += $unk;
     47     $hits{errors} += $err;
     48 
     49     for my $k (sort (keys (%hits))) {
     50 	print ("$k=$hits{$k} ");
     51     }
     52     print ("\n");
     53 
     54     # select (undef, undef, undef, 0.2);
     55 };