]> granicus.if.org Git - apache/commitdiff
Updates patch provided by Dave Brondsema (brondsem AT apache org) four
authorRich Bowen <rbowen@apache.org>
Thu, 12 Apr 2012 12:25:48 +0000 (12:25 +0000)
committerRich Bowen <rbowen@apache.org>
Thu, 12 Apr 2012 12:25:48 +0000 (12:25 +0000)
years ago, makes the script strict/warnings compliant, and updates to
current output format of server-status.
Partially fixes https://issues.apache.org/bugzilla/show_bug.cgi?id=45424
The script now actually produces output.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1325218 13f79535-47bb-0310-9956-ffa450edef68

support/log_server_status.in

index b788ab191364af1276e0b8596b4835845f160a46..6f0505f05d7674b24370d943d940abf916a31ded 100644 (file)
 # it to a file.  Make sure the directory $wherelog is writable by the
 # user who runs this script.
 #
-require 'sys/socket.ph';
+use Socket;
+use strict;
+use warnings;
 
-$wherelog = "/var/log/graph/";  # Logs will be like "/var/log/graph/19960312"
-$server = "localhost";          # Name of server, could be "www.foo.com"
-$port = "80";                   # Port on server
-$request = "/status/?auto";     # Request to send
+my $wherelog = "/var/log/httpd/";  # Logs will be like "/var/log/graph/19960312"
+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
 {
-       local($host,$port) =@_;
-        $sockaddr='S n a4 x8';
-        chop($hostname=`hostname`);
-        $port=(getservbyname($port, 'tcp'))[2]  unless $port =~ /^\d+$/;
-        $me=pack($sockaddr,&AF_INET,0,(gethostbyname($hostname))[4]);
-        $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 ( $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 "";
 }
 
 ### Main
 
 {
-        $year=`date +%y`;
-       chomp($year);
-       $year += ($year < 70) ? 2000 : 1900;
-       $date = $year . `date +%m%d:%H%M%S`;
-       chomp($date);
-       ($day,$time)=split(/:/,$date);
-       $res=&tcp_connect($server,$port);
-       open(OUT,">>$wherelog$day");
-       if ($res) {
-               print OUT "$time:-1:-1:-1:-1:$res\n";
-               exit 1;
-       }
-       print S "GET $request\n";
-       while (<S>) {
-               $requests=$1 if ( m|^BusyServers:\ (\S+)|);
-               $idle=$1 if ( m|^IdleServers:\ (\S+)|);
-               $number=$1 if ( m|sses:\ (\S+)|);
-               $cpu=$1 if (m|^CPULoad:\ (\S+)|);
-       }
-       print OUT "$time:$requests:$idle:$number:$cpu\n";
+    my $year = `date +%y`;
+    chomp($year);
+    $year += ( $year < 70 ) ? 2000 : 1900;
+    my $date = $year . `date +%m%d:%H%M%S`;
+    chomp($date);
+    my ( $day, $time ) = split( /:/, $date );
+    my $res = &tcp_connect( $server, $port );
+    open( OUT, ">>$wherelog$day" );
+
+    if ($res) {
+        print OUT "$time:-1:-1:-1:-1:$res\n";
+        exit 1;
+    }
+    print S "GET $request\n";
+    my ( $requests, $idle, $number, $cpu );
+    while (<S>) {
+        $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";
 }