<% Z::import_query_string; $::f{"help"} = "/apps/web/docs/controller/cluster.html"; $::f{"title"} = "Cluster Status"; Z::parse( "../etc/clusterheader.ahtml" ); Z::addheader( "Cache-Control", "no-cache" ); use ZeusOS; $O_RDONLY = $ZeusOS::O_RDONLY; $O_WRONLY = $ZeusOS::O_WRONLY; ############################################################################# # Check for auto-refresh $refresh = 0; $script_name = $ENV{REQUEST_URI}; $script_name =~ s/\?.*//; if ( defined $::f{refresh} && $::f{refresh} eq "yes" ) { $refresh = 1; Z::write(''); } ## ## Draws a pictorial representation of the current server status ## ## Requries ## single-black.gif ## server.gif ## deadserver.gif sub draw_status() { # List of backend machines (host:port) my $hostsfile = "$ENV{ZEUSHOME}/webadmin/conf/hosts"; # List of frontend load-balancers (host:port) my $lbsfile ="$ENV{ZEUSHOME}/webadmin/conf/lbs"; # Get current time (used to generate unique URLs for machines) $time = time; $count = $time; # ---------------------------------------------------------- # Get hosts sysopen( F, "$hostsfile", $O_RDONLY ) or ::Error( "Could not open hosts file" ); my @backends_unsorted = ; close F; chomp @backends_unsorted; my @backends = sort @backends_unsorted; # this may not exist if Zeus Balancer has not been installed, so we # have to do something if that happens my @frontends = (); if ( sysopen( F, "$lbsfile", $O_RDONLY ) ) { my @frontends_unsorted = ; close F; chomp @frontends_unsorted; @frontends = sort @frontends_unsorted; } else { # no frontends } # If there are any frontends, there should be 1 or 2 of them # if ( scalar @frontends > 2 ) { Z::write( "

Warning: " . scalar @frontends . " frontends defined. "); Z::write("There is a maximum of 2!

"); } my $lowsrc; if ( $refresh ) { $lowsrc = ""; # "loading" image } else { $lowsrc = 'lowsrc="timeserver.gif"'; } ## Now lets think about our table # # |-------------------------------------------------| # |backend1|...|backend2|....|backend3|....|backend4| # --------------------------------------------------- # or like this: # |-------------------------------------------------| # |..........|frontend1|........|frontend2|.........| # |-------------------------------------------------| # |backend1|...|backend2|....|backend3|....|backend4| # --------------------------------------------------- # Work out how many frontends we have my $columns = scalar @frontends; # Start our table Z::write("
\n"); # We need a router! $tmp =< HERE Z::write( $tmp ); # Now the bus onto frontend connections (if there is a frontend) if ( scalar @frontends ) { # Our bus $tmp = < HERE Z::write( $tmp ); # Write our frontend row Z::write( "" ); foreach $i ( @frontends ) { my $hostname = &hostname( $i ); my ( $machine, $port ) = split /:/, $i; my $image = <
${hostname}
HERE Z::write( $image ); } Z::write("
\n" ); # Now our frontend onto bus row Z::write( "" ); foreach $i ( @frontends ) { Z::write(""); } Z::write( "\n" ); } Z::write( "

\n" ); my $image_width = 66; my $image_height = 106; my $small = 'no'; my $max_width = 440; my $first_row = 1; while ( @backends ) { # Start a new table, so we can space out backends separately Z::write( "" ); my $num_backends = scalar @backends; my $spacing = $max_width / $num_backends; if ( $spacing < $image_width + 6 ) { $small = 'yes'; $image_width = 33; $image_height = 53; if ( $lowsrc != "" ) { $lowsrc = "lowsrc=\"mini-timeserver.gif\""; } $spacing = $max_width / $num_backends; if ( $spacing < $image_width + 12 ) { $spacing = $image_width + 12; } } if ( $spacing > $image_width + 60 ) { $spacing = $image_width + 60; } # How many servers can fit onto a row? my $per_row = int( $max_width / $spacing ); my $i = $per_row + 1; if ( $first_row && $per_row >= $num_backends ) { $tmp = < HERE Z::write( $tmp ); } else { $tmp = < HERE Z::write( $tmp ); } # Now the backend onto bus row Z::write(""); if ( $per_row >= $num_backends ) { $per_row = $num_backends } else { Z::write("\n"); } for( my $i=0; $i < $per_row; $i++ ) { my $box = shift @backends; my $hostname = &hostname( $box ); my ( $machine, $port ) = split /:/, $box; my $image = <
$hostname


HERE Z::write( $image ); } # All done Z::write( "
\n
\n" ); $first_row = 0; } Z::write "
"; } # ---------------------------------------------------------- # Returns the response time in ms sub getstats { my ( $backend ) = @_; # TODO return ""; } # ---------------------------------------------------------- # Returns the short hostname of a machine given its full name sub hostname { my ( $fullname ) = @_; my ( $hostonly ) = split /:/, $fullname, 1; # Check if this hostname is just an IP address if ( $hostonly =~ /\d+\.\d+\.\d+\.\d+/ ) { # IP address return $hostonly; } else { ( $hostonly ) = split /\./, $hostonly, 1; return $hostonly; } } ############################################################################## %> Zeus Web Server has been designed to easily manage a cluster of machines with a common configuration. This page lets you view and configure your cluster setup. Click on a server icon to view the status of the server. Click on the book icon for more information about setting up a cluster.

<% if ( $refresh ) { Z::write( "Disable auto-refresh" ); } else { Z::write( "Enable auto-refresh" ); } %>      Configuration      Summary
<%Z::parse( "../etc/footer.ahtml" )%>