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
10
# http://www.apache.org/licenses/LICENSE-2.0
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.
20
# Mark J Cox, UK Web Ltd 1996, mark ukweb.com
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.
28
require 'sys/socket.ph';
30
$wherelog = "/var/log/graph/"; # Logs will be like "/var/log/graph/19960312"
31
$server = "localhost"; # Name of server, could be "www.foo.com"
32
$port = "80"; # Port on server
33
$request = "/status/?auto"; # Request to send
37
local($host,$port) =@_;
38
$sockaddr='S n a4 x8';
39
chop($hostname=`hostname`);
40
$port=(getservbyname($port, 'tcp'))[2] unless $port =~ /^\d+$/;
41
$me=pack($sockaddr,&AF_INET,0,(gethostbyname($hostname))[4]);
42
$them=pack($sockaddr,&AF_INET,$port,(gethostbyname($host))[4]);
43
socket(S,&PF_INET,&SOCK_STREAM,(getprotobyname('tcp'))[2]) ||
45
bind(S,$me) || return "bind: $!";
46
connect(S,$them) || return "connect: $!";
58
$year += ($year < 70) ? 2000 : 1900;
59
$date = $year . `date +%m%d:%H%M%S`;
61
($day,$time)=split(/:/,$date);
62
$res=&tcp_connect($server,$port);
63
open(OUT,">>$wherelog$day");
65
print OUT "$time:-1:-1:-1:-1:$res\n";
68
print S "GET $request\n";
70
$requests=$1 if ( m|^BusyServers:\ (\S+)|);
71
$idle=$1 if ( m|^IdleServers:\ (\S+)|);
72
$number=$1 if ( m|sses:\ (\S+)|);
73
$cpu=$1 if (m|^CPULoad:\ (\S+)|);
75
print OUT "$time:$requests:$idle:$number:$cpu\n";