log_server_status revision 09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1
688N/A#!/usr/local/bin/perl
1619N/A
688N/A# ====================================================================
688N/A# Copyright (c) 1995-1999 The Apache Group. All rights reserved.
919N/A#
919N/A# Redistribution and use in source and binary forms, with or without
919N/A# modification, are permitted provided that the following conditions
919N/A# are met:
919N/A#
919N/A# 1. Redistributions of source code must retain the above copyright
919N/A# notice, this list of conditions and the following disclaimer.
919N/A#
919N/A# 2. Redistributions in binary form must reproduce the above copyright
919N/A# notice, this list of conditions and the following disclaimer in
919N/A# the documentation and/or other materials provided with the
919N/A# distribution.
919N/A#
919N/A# 3. All advertising materials mentioning features or use of this
919N/A# software must display the following acknowledgment:
919N/A# "This product includes software developed by the Apache Group
919N/A# for use in the Apache HTTP server project (http://www.apache.org/)."
688N/A#
688N/A# 4. The names "Apache Server" and "Apache Group" must not be used to
1408N/A# endorse or promote products derived from this software without
1408N/A# prior written permission. For written permission, please contact
1408N/A# apache@apache.org.
1408N/A#
962N/A# 5. Products derived from this software may not be called "Apache"
688N/A# nor may "Apache" appear in their names without prior written
688N/A# permission of the Apache Group.
688N/A#
688N/A# 6. Redistributions of any form whatsoever must retain the following
688N/A# acknowledgment:
688N/A# "This product includes software developed by the Apache Group
688N/A# for use in the Apache HTTP server project (http://www.apache.org/)."
962N/A#
719N/A# THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
719N/A# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
719N/A# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
962N/A# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
962N/A# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
962N/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
962N/A# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
962N/A# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
962N/A# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
962N/A# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
962N/A# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
719N/A# OF THE POSSIBILITY OF SUCH DAMAGE.
719N/A# ====================================================================
719N/A#
719N/A# This software consists of voluntary contributions made by many
719N/A# individuals on behalf of the Apache Group and was originally based
719N/A# on public domain software written at the National Center for
719N/A# Supercomputing Applications, University of Illinois, Urbana-Champaign.
719N/A# For more information on the Apache Group and the Apache HTTP server
962N/A# project, please see <http://www.apache.org/>.
962N/A
962N/A
719N/A# Log Server Status
719N/A# Mark J Cox, UK Web Ltd 1996, mark@ukweb.com
719N/A#
962N/A# This script is designed to be run at a frequent interval by something
719N/A# like cron. It connects to the server and downloads the status
719N/A# information. It reformats the information to a single line and logs
719N/A# it to a file. Make sure the directory $wherelog is writable by the
719N/A# user who runs this script.
719N/A#
719N/Arequire 'sys/socket.ph';
719N/A
719N/A$wherelog = "/var/log/graph/"; # Logs will be like "/var/log/graph/19960312"
962N/A$server = "localhost"; # Name of server, could be "www.foo.com"
719N/A$port = "80"; # Port on server
719N/A$request = "/status/?auto"; # Request to send
719N/A
719N/Asub tcp_connect
719N/A{
719N/A local($host,$port) =@_;
719N/A $sockaddr='S n a4 x8';
719N/A chop($hostname=`hostname`);
962N/A $port=(getservbyname($port, 'tcp'))[2] unless $port =~ /^\d+$/;
719N/A $me=pack($sockaddr,&AF_INET,0,(gethostbyname($hostname))[4]);
719N/A $them=pack($sockaddr,&AF_INET,$port,(gethostbyname($host))[4]);
719N/A socket(S,&PF_INET,&SOCK_STREAM,(getprotobyname('tcp'))[2]) ||
719N/A die "socket: $!";
719N/A bind(S,$me) || return "bind: $!";
719N/A connect(S,$them) || return "connect: $!";
719N/A select(S);
719N/A $| = 1;
962N/A select(stdout);
719N/A return "";
719N/A}
719N/A
719N/A### Main
719N/A
719N/A{
719N/A $year=`date +%y`;
719N/A chomp($year);
719N/A $year += ($year < 70) ? 2000 : 1900;
719N/A $date = $year . `date +%m%d:%H%M%S`;
719N/A chomp($date);
719N/A ($day,$time)=split(/:/,$date);
719N/A $res=&tcp_connect($server,$port);
719N/A open(OUT,">>$wherelog$day");
719N/A if ($res) {
719N/A print OUT "$time:-1:-1:-1:-1:$res\n";
719N/A exit 1;
719N/A }
719N/A print S "GET $request\n";
719N/A while (<S>) {
962N/A $requests=$1 if ( m|^BusyServers:\ (\S+)|);
719N/A $idle=$1 if ( m|^IdleServers:\ (\S+)|);
719N/A $number=$1 if ( m|sses:\ (\S+)|);
688N/A $cpu=$1 if (m|^CPULoad:\ (\S+)|);
719N/A }
719N/A print OUT "$time:$requests:$idle:$number:$cpu\n";
688N/A}
688N/A
688N/A
688N/A