home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / support / log_server_status < prev    next >
Encoding:
Text File  |  1999-01-01  |  4.4 KB  |  116 lines

  1. #!/usr/local/bin/perl
  2.  
  3. # ====================================================================
  4. # Copyright (c) 1995-1999 The Apache Group.  All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. #
  10. # 1. Redistributions of source code must retain the above copyright
  11. #    notice, this list of conditions and the following disclaimer. 
  12. #
  13. # 2. Redistributions in binary form must reproduce the above copyright
  14. #    notice, this list of conditions and the following disclaimer in
  15. #    the documentation and/or other materials provided with the
  16. #    distribution.
  17. #
  18. # 3. All advertising materials mentioning features or use of this
  19. #    software must display the following acknowledgment:
  20. #    "This product includes software developed by the Apache Group
  21. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  22. #
  23. # 4. The names "Apache Server" and "Apache Group" must not be used to
  24. #    endorse or promote products derived from this software without
  25. #    prior written permission. For written permission, please contact
  26. #    apache@apache.org.
  27. #
  28. # 5. Products derived from this software may not be called "Apache"
  29. #    nor may "Apache" appear in their names without prior written
  30. #    permission of the Apache Group.
  31. #
  32. # 6. Redistributions of any form whatsoever must retain the following
  33. #    acknowledgment:
  34. #    "This product includes software developed by the Apache Group
  35. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  36. #
  37. # THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  38. # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  39. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  40. # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  41. # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  43. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  44. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  46. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  47. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  48. # OF THE POSSIBILITY OF SUCH DAMAGE.
  49. # ====================================================================
  50. #
  51. # This software consists of voluntary contributions made by many
  52. # individuals on behalf of the Apache Group and was originally based
  53. # on public domain software written at the National Center for
  54. # Supercomputing Applications, University of Illinois, Urbana-Champaign.
  55. # For more information on the Apache Group and the Apache HTTP server
  56. # project, please see <http://www.apache.org/>.
  57.  
  58.  
  59. # Log Server Status
  60. # Mark J Cox, UK Web Ltd 1996, mark@ukweb.com
  61. #
  62. # This script is designed to be run at a frequent interval by something
  63. # like cron.  It connects to the server and downloads the status
  64. # information.  It reformats the information to a single line and logs
  65. # it to a file.  Make sure the directory $wherelog is writable by the
  66. # user who runs this script.
  67. #
  68. require 'sys/socket.ph';
  69.  
  70. $wherelog = "/var/log/graph/";  # Logs will be like "/var/log/graph/960312"
  71. $server = "localhost";          # Name of server, could be "www.foo.com"
  72. $port = "80";                   # Port on server
  73. $request = "/status/?auto";     # Request to send
  74.  
  75. sub tcp_connect
  76. {
  77.     local($host,$port) =@_;
  78.         $sockaddr='S n a4 x8';
  79.         chop($hostname=`hostname`);
  80.         $port=(getservbyname($port, 'tcp'))[2]  unless $port =~ /^\d+$/;
  81.         $me=pack($sockaddr,&AF_INET,0,(gethostbyname($hostname))[4]);
  82.         $them=pack($sockaddr,&AF_INET,$port,(gethostbyname($host))[4]);
  83.         socket(S,&PF_INET,&SOCK_STREAM,(getprotobyname('tcp'))[2]) || 
  84.         die "socket: $!";
  85.         bind(S,$me) || return "bind: $!";
  86.         connect(S,$them) || return "connect: $!";
  87.         select(S); 
  88.     $| = 1; 
  89.     select(stdout);
  90.     return "";
  91. }
  92.  
  93. ### Main
  94.  
  95. {
  96.     $date=`date +%y%m%d:%H%M%S`;
  97.     chop($date);
  98.     ($day,$time)=split(/:/,$date);
  99.     $res=&tcp_connect($server,$port);
  100.     open(OUT,">>$wherelog$day");
  101.     if ($res) {
  102.         print OUT "$time:-1:-1:-1:-1:$res\n";
  103.         exit 1;
  104.     }
  105.     print S "GET $request\n";
  106.     while (<S>) {
  107.         $requests=$1 if ( m|^BusyServers:\ (\S+)|);
  108.         $idle=$1 if ( m|^IdleServers:\ (\S+)|);
  109.         $number=$1 if ( m|sses:\ (\S+)|);
  110.         $cpu=$1 if (m|^CPULoad:\ (\S+)|);
  111.     }
  112.     print OUT "$time:$requests:$idle:$number:$cpu\n";
  113. }
  114.  
  115.  
  116.