bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / support / log_server_status.in
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 #
28 require 'sys/socket.ph';
29
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
34
35 sub tcp_connect
36 {
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]) || 
44                 die "socket: $!";
45         bind(S,$me) || return "bind: $!";
46         connect(S,$them) || return "connect: $!";
47         select(S); 
48         $| = 1; 
49         select(stdout);
50         return "";
51 }
52
53 ### Main
54
55 {
56         $year=`date +%y`;
57         chomp($year);
58         $year += ($year < 70) ? 2000 : 1900;
59         $date = $year . `date +%m%d:%H%M%S`;
60         chomp($date);
61         ($day,$time)=split(/:/,$date);
62         $res=&tcp_connect($server,$port);
63         open(OUT,">>$wherelog$day");
64         if ($res) {
65                 print OUT "$time:-1:-1:-1:-1:$res\n";
66                 exit 1;
67         }
68         print S "GET $request\n";
69         while (<S>) {
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+)|);
74         }
75         print OUT "$time:$requests:$idle:$number:$cpu\n";
76 }
77
78