From: Rich Bowen Date: Thu, 12 Apr 2012 13:34:16 +0000 (+0000) Subject: With further assistance from Daniel Gruno - style changes, removes use X-Git-Tag: 2.5.0-alpha~7191 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=50e5ebcf37e5dc1f2f45f5d8c8cc620f678615f6;p=apache With further assistance from Daniel Gruno - style changes, removes use of `hostname`, uses IO::Socket instead of a custom tcp_connect function, and uses HTTP/1.1. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1325250 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/support/log_server_status.in b/support/log_server_status.in index bf9d684020..1e72b80fc2 100644 --- a/support/log_server_status.in +++ b/support/log_server_status.in @@ -25,7 +25,7 @@ # it to a file. Make sure the directory $wherelog is writable by the # user who runs this script. # -use Socket; +use IO::Socket; use strict; use warnings; @@ -34,55 +34,43 @@ my $server = "localhost"; # Name of server, could be "www.foo.com" my $port = "80"; # Port on server my $request = "/server-status/?auto"; # Request to send -sub tcp_connect -{ - my ( $host, $port ) = @_; - my $sockaddr = 'S n a4 x8'; - chop( my $hostname = `hostname` ); - $port = ( getservbyname( $port, 'tcp' ) )[2] unless $port =~ /^\d+$/; - my $me = pack( $sockaddr, &AF_INET, 0, ( gethostbyname($hostname) )[4] ); - my $them = pack( $sockaddr, &AF_INET, $port, ( gethostbyname($host) )[4] ); - socket( S, &PF_INET, &SOCK_STREAM, ( getprotobyname('tcp') )[2] ) - || die "socket: $!"; - bind( S, $me ) || return "bind: $!"; - connect( S, $them ) || return "connect: $!"; - select(S); - $| = 1; - select(STDOUT); - return ""; -} +my @ltime = localtime(time); -### Main +my $day = + $ltime[5] + 1900 + . sprintf( "%02d", $ltime[4] + 1 ) + . sprintf( "%02d", $ltime[3] ); -{ - my @ltime = localtime(time); - - my $day = - $ltime[5] + 1900 - . sprintf( "%02d", $ltime[4] + 1 ) - . sprintf( "%02d", $ltime[3] ); +my $time = + sprintf( "%02d", $ltime[2] ) + . sprintf( "%02d", $ltime[1] ) + . sprintf( "%02d", $ltime[0] ); - my $time = - sprintf( "%02d", $ltime[2] ) - . sprintf( "%02d", $ltime[1] ) - . sprintf( "%02d", $ltime[0] ); +open(OUT,">>$wherelog$day"); - my $res = &tcp_connect( $server, $port ); - open( OUT, ">>$wherelog$day" ); +my $socket = new IO::Socket::INET( + PeerAddr => $server, + PeerPort => $port, + Proto => "tcp", + Type => SOCK_STREAM + ) + or do { + print OUT "$time:-1:-1:-1:-1:$@\n"; + close OUT; + die "Couldn't connect to $server:$port : $@\n"; + }; +$| = 1; - if ($res) { - print OUT "$time:-1:-1:-1:-1:$res\n"; - exit 1; - } - print S "GET $request\n"; - my ( $requests, $idle, $number, $cpu ); - while () { - $requests = $1 if (m|^BusyWorkers:\ (\S+)|); - $idle = $1 if (m|^IdleWorkers:\ (\S+)|); - $number = $1 if (m|sses:\ (\S+)|); - $cpu = $1 if (m|^CPULoad:\ (\S+)|); - } - print OUT "$time:$requests:$idle:$number:$cpu\n"; -} +print $socket + "GET $request HTTP/1.1\r\nHost: $server\r\nConnection: close\r\n\r\n\r\n"; +my ( $requests, $idle, $number, $cpu ); +while (<$socket>) { + $requests = $1 if (m|^BusyWorkers:\ (\S+)|); + $idle = $1 if (m|^IdleWorkers:\ (\S+)|); + $number = $1 if (m|sses:\ (\S+)|); + $cpu = $1 if (m|^CPULoad:\ (\S+)|); +} +print OUT "$time:$requests:$idle:$number:$cpu\n"; +close OUT;