Blame support/log_server_status.in

Packit 90a5c9
#!@perlbin@
Packit 90a5c9
#
Packit 90a5c9
# Licensed to the Apache Software Foundation (ASF) under one or more
Packit 90a5c9
# contributor license agreements.  See the NOTICE file distributed with
Packit 90a5c9
# this work for additional information regarding copyright ownership.
Packit 90a5c9
# The ASF licenses this file to You under the Apache License, Version 2.0
Packit 90a5c9
# (the "License"); you may not use this file except in compliance with
Packit 90a5c9
# the License.  You may obtain a copy of the License at
Packit 90a5c9
#
Packit 90a5c9
#     http://www.apache.org/licenses/LICENSE-2.0
Packit 90a5c9
#
Packit 90a5c9
# Unless required by applicable law or agreed to in writing, software
Packit 90a5c9
# distributed under the License is distributed on an "AS IS" BASIS,
Packit 90a5c9
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 90a5c9
# See the License for the specific language governing permissions and
Packit 90a5c9
# limitations under the License.
Packit 90a5c9
#
Packit 90a5c9
#
Packit 90a5c9
# Log Server Status
Packit 90a5c9
# Mark J Cox, UK Web Ltd 1996, mark ukweb.com
Packit 90a5c9
#
Packit 90a5c9
# This script is designed to be run at a frequent interval by something
Packit 90a5c9
# like cron.  It connects to the server and downloads the status
Packit 90a5c9
# information.  It reformats the information to a single line and logs
Packit 90a5c9
# it to a file.  Make sure the directory $wherelog is writable by the
Packit 90a5c9
# user who runs this script.
Packit 90a5c9
#
Packit 90a5c9
use IO::Socket;
Packit 90a5c9
use strict;
Packit 90a5c9
use warnings;
Packit 90a5c9
Packit 90a5c9
my $wherelog = "@exp_logfiledir@/";  # Logs will be like "@exp_logfiledir@/19960312"
Packit 90a5c9
my $server   = "localhost";        # Name of server, could be "www.foo.com"
Packit 90a5c9
my $port     = "@PORT@";               # Port on server
Packit 90a5c9
my $request = "/server-status/?auto";    # Request to send
Packit 90a5c9
Packit 90a5c9
my @ltime = localtime(time);
Packit 90a5c9
Packit 90a5c9
my $day =
Packit 90a5c9
    $ltime[5] + 1900
Packit 90a5c9
  . sprintf( "%02d", $ltime[4] + 1 )
Packit 90a5c9
  . sprintf( "%02d", $ltime[3] );
Packit 90a5c9
Packit 90a5c9
my $time =
Packit 90a5c9
    sprintf( "%02d", $ltime[2] )
Packit 90a5c9
  . sprintf( "%02d", $ltime[1] )
Packit 90a5c9
  . sprintf( "%02d", $ltime[0] );
Packit 90a5c9
Packit 90a5c9
open(OUT,">>$wherelog$day");
Packit 90a5c9
Packit 90a5c9
my $socket = new IO::Socket::INET(
Packit 90a5c9
    PeerAddr => $server,
Packit 90a5c9
    PeerPort => $port,
Packit 90a5c9
    Proto    => "tcp",
Packit 90a5c9
    Type     => SOCK_STREAM
Packit 90a5c9
  )
Packit 90a5c9
  or do {
Packit 90a5c9
    print OUT "$time:-1:-1:-1:-1:$@\n";
Packit 90a5c9
    close OUT;
Packit 90a5c9
    die "Couldn't connect to $server:$port : $@\n";
Packit 90a5c9
  };
Packit 90a5c9
$| = 1;
Packit 90a5c9
Packit 90a5c9
print $socket
Packit 90a5c9
  "GET $request HTTP/1.1\r\nHost: $server\r\nConnection: close\r\n\r\n\r\n";
Packit 90a5c9
Packit 90a5c9
my ( $requests, $idle, $number, $cpu );
Packit 90a5c9
while (<$socket>) {
Packit 90a5c9
    $requests = $1 if (m|^BusyWorkers:\ (\S+)|);
Packit 90a5c9
    $idle     = $1 if (m|^IdleWorkers:\ (\S+)|);
Packit 90a5c9
    $number   = $1 if (m|sses:\ (\S+)|);
Packit 90a5c9
    $cpu      = $1 if (m|^CPULoad:\ (\S+)|);
Packit 90a5c9
}
Packit 90a5c9
print OUT "$time:$requests:$idle:$number:$cpu\n";
Packit 90a5c9
close OUT;
Packit 90a5c9