1#!@perlbin@ 2# 3# Licensed to the Apache Software Foundation (ASF) under one or more 4# contributor license agreements. See the NOTICE file distributed with 5# this work for additional information regarding copyright ownership. 6# The ASF licenses this file to You under the Apache License, Version 2.0 7# (the "License"); you may not use this file except in compliance with 8# the License. You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18# 19# Log Server Status 20# Mark J Cox, UK Web Ltd 1996, mark ukweb.com 21# 22# This script is designed to be run at a frequent interval by something 23# like cron. It connects to the server and downloads the status 24# information. It reformats the information to a single line and logs 25# it to a file. Make sure the directory $wherelog is writable by the 26# user who runs this script. 27# 28use IO::Socket; 29use strict; 30use warnings; 31 32my $wherelog = "@exp_logfiledir@/"; # Logs will be like "@exp_logfiledir@/19960312" 33my $server = "localhost"; # Name of server, could be "www.foo.com" 34my $port = "@PORT@"; # Port on server 35my $request = "/server-status/?auto"; # Request to send 36 37my @ltime = localtime(time); 38 39my $day = 40 $ltime[5] + 1900 41 . sprintf( "%02d", $ltime[4] + 1 ) 42 . sprintf( "%02d", $ltime[3] ); 43 44my $time = 45 sprintf( "%02d", $ltime[2] ) 46 . sprintf( "%02d", $ltime[1] ) 47 . sprintf( "%02d", $ltime[0] ); 48 49open(OUT,">>$wherelog$day"); 50 51my $socket = new IO::Socket::INET( 52 PeerAddr => $server, 53 PeerPort => $port, 54 Proto => "tcp", 55 Type => SOCK_STREAM 56 ) 57 or do { 58 print OUT "$time:-1:-1:-1:-1:$@\n"; 59 close OUT; 60 die "Couldn't connect to $server:$port : $@\n"; 61 }; 62$| = 1; 63 64print $socket 65 "GET $request HTTP/1.1\r\nHost: $server\r\nConnection: close\r\n\r\n\r\n"; 66 67my ( $requests, $idle, $number, $cpu ); 68while (<$socket>) { 69 $requests = $1 if (m|^BusyWorkers:\ (\S+)|); 70 $idle = $1 if (m|^IdleWorkers:\ (\S+)|); 71 $number = $1 if (m|sses:\ (\S+)|); 72 $cpu = $1 if (m|^CPULoad:\ (\S+)|); 73} 74print OUT "$time:$requests:$idle:$number:$cpu\n"; 75close OUT; 76 77