monit-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Monitoring Apache mod_status (was Apache, rotatelogs & chroot environmen


From: David Fletcher
Subject: Monitoring Apache mod_status (was Apache, rotatelogs & chroot environment)
Date: Fri, 10 Dec 2004 11:54:29 +0000

Hi,

Here is are the code and documenation patchs for monitoring Apache's mod_status
that has been discussed on the Monit-General list.

I hope that it survives line wrapping - some of the lines were 80 characters,
but have been made a little longer by the patch creation. Some of the "diff"
file name lines also extend beyond 80 characters.

The first patch is for the Monit 4.4 code, the second is for the monit.dep
documentation file.

David.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1) Code patch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff -Naur monit-4.4/l.l monit-4.4-patched/l.l
--- monit-4.4/l.l       2004-05-06 00:06:51.000000000 +0100
+++ monit-4.4-patched/l.l       2004-12-09 17:47:26.000000000 +0000
@@ -174,6 +174,7 @@
 host              { return HOST; }
 default           { return DEFAULT; }
 http              { return HTTP; }
+apache-status     { return APACHESTATUS; }
 ftp               { return FTP; }
 smtp              { return SMTP; }
 pop               { return POP; }
@@ -193,6 +194,16 @@
 uid               { return UID; }
 gid               { return GID; }
 request           { return REQUEST; }
+loglimit          { return LOGLIMIT; }
+closelimit        { return CLOSELIMIT; }
+dnslimit          { return DNSLIMIT; }
+keepalivelimit    { return KEEPALIVELIMIT; }
+replylimit        { return REPLYLIMIT; }
+requestlimit      { return REQUESTLIMIT; }
+startlimit        { return STARTLIMIT; }
+waitlimit         { return WAITLIMIT; }
+gracefullimit     { return GRACEFULLIMIT; }
+cleanuplimit      { return CLEANUPLIMIT; }
 cpuusage          { return CPUUSAGE; }
 memusage          { return MEMUSAGE; }
 memkbyte          { return MEMKBYTE; }
diff -Naur monit-4.4/monitor.h monit-4.4-patched/monitor.h
--- monit-4.4/monitor.h 2004-09-10 20:13:58.000000000 +0100
+++ monit-4.4-patched/monitor.h 2004-12-09 23:32:25.000000000 +0000
@@ -388,6 +388,20 @@
   int is_available;                /**< TRUE if the server/port is available */
   double response;                      /**< Socket connection response time */
   EventAction_T action;  /**< Description of the action upon event occurence */
+
+  /**< Apache-status specific parameters */
+  struct apache_status {
+    int loglimit;                  /**< Max percentatge of logging processes */
+    int closelimit;             /**< Max percentatge of closinging processes */
+    int dnslimit;         /**< Max percentatge of processes doing DNS lookup */
+    int keepalivelimit;          /**< Max percentatge of keepalive processes */
+    int replylimit;               /**< Max percentatge of replying processes */
+    int requestlimit;     /**< Max percentatge of processes reading requests */
+    int startlimit;            /**< Max percentatge of processes starting up */
+    int waitlimit;  /**< Min percentatge of processes waiting for connection */
+    int gracefullimit;/**< Max percentatge of processes gracefully finishing */
+    int cleanuplimit;      /**< Max percentatge of processes in idle cleanup */
+  } ApacheStatus;
   
   struct {
     int use_ssl;          /**< TRUE if this port requires SSL for connection */
@@ -722,6 +736,7 @@
 int  check_remote_host(Service_T);
 int  sha_md5_stream (FILE *, void *, void *);
 void reset_procinfo(Service_T);
+char *get_host_header(Socket_T s, char *buf, int len);
 void printhash(char *);  
 
 #endif
diff -Naur monit-4.4/p.y monit-4.4-patched/p.y
--- monit-4.4/p.y       2004-09-17 19:59:44.000000000 +0100
+++ monit-4.4-patched/p.y       2004-12-09 23:30:59.000000000 +0000
@@ -129,6 +129,17 @@
     char *pathname;
     char *request;
     char *request_checksum;
+    int  apcstat_loglimit;
+    int  apcstat_closelimit;
+    int  apcstat_dnslimit;
+    int  apcstat_keepalivelimit;
+    int  apcstat_replylimit;
+    int  apcstat_requestlimit;
+    int  apcstat_startlimit;
+    int  apcstat_waitlimit;
+    int  apcstat_gracefullimit;
+    int  apcstat_cleanuplimit;
+    int  apcstat_idlelimit;
     Generic_T generic;
     Protocol_T protocol;
     EventAction_T action;
@@ -224,8 +235,8 @@
   static Service_T depend_list= NULL;
   static struct IHavePrecedence ihp= {FALSE, FALSE, FALSE};
   static struct PortSet portset= {-1, 0, SOCK_STREAM, AF_INET, FALSE,
-    SSL_VERSION_AUTO, NET_TIMEOUT, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-    NULL};
+    SSL_VERSION_AUTO, NET_TIMEOUT, NULL, NULL, NULL, NULL, NULL, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL};
   static struct ResourceSet resourceset= {0, 0, OPERATOR_EQUAL, 1, NULL};
   static struct TimestampSet timestampset= {OPERATOR_EQUAL, 0, FALSE, TRUE, 
NULL};
   static struct SizeSet sizeset= {OPERATOR_EQUAL, 0, FALSE, TRUE, NULL};
@@ -309,10 +320,13 @@
 %token HOST PORT TYPE UDP TCP TCPSSL PROTOCOL CONNECTION
 %token ALERT MAILFORMAT UNIXSOCKET SIGNATURE
 %token TIMEOUT RESTART CHECKSUM EXPECT EVERY 
-%token DEFAULT HTTP FTP SMTP POP IMAP NNTP SSH DWP LDAP2 LDAP3 RDATE RSYNC
+%token DEFAULT HTTP APACHESTATUS FTP SMTP POP IMAP NNTP 
+%token SSH DWP LDAP2 LDAP3 RDATE RSYNC
 %token <string> STRING PATH MAILADDR MAILFROM MAILSUBJECT
 %token <string> MAILBODY SERVICENAME
-%token <number> NUMBER PERCENT
+%token <number> NUMBER PERCENT LOGLIMIT CLOSELIMIT DNSLIMIT KEEPALIVELIMIT 
+%token <number> REPLYLIMIT REQUESTLIMIT STARTLIMIT WAITLIMIT GRACEFULLIMIT 
+%token <number> CLEANUPLIMIT 
 %token <real> REAL
 %token CHECKPROC CHECKDEV CHECKFILE CHECKDIR CHECKHOST
 %token CPUUSAGE MEMUSAGE MEMKBYTE CHILDREN 
@@ -780,6 +794,8 @@
 protocol        : /* EMPTY */  { portset.protocol= addprotocol(P_DEFAULT);}
                 | PROTOCOL DEFAULT { portset.protocol= addprotocol(P_DEFAULT); 
}
                 | PROTOCOL HTTP request {portset.protocol= 
addprotocol(P_HTTP);}
+                | PROTOCOL APACHESTATUS apache_stat_list {
+                 portset.protocol= addprotocol(P_APACHESTATUS);}
                 | PROTOCOL FTP { portset.protocol= addprotocol(P_FTP); }
                 | PROTOCOL SMTP { portset.protocol= addprotocol(P_SMTP); }
                 | PROTOCOL POP { portset.protocol= addprotocol(P_POP); }
@@ -810,6 +826,22 @@
                  }
                 ;
 
+apache_stat_list: /* EMPTY */
+                | apache_stat_list apache_stat
+                ;
+
+apache_stat     : LOGLIMIT NUMBER { portset.apcstat_loglimit = $2; }
+                | CLOSELIMIT NUMBER { portset.apcstat_closelimit = $2; }
+                | DNSLIMIT NUMBER { portset.apcstat_dnslimit = $2; }
+                | KEEPALIVELIMIT NUMBER { portset.apcstat_keepalivelimit = $2; 
}
+                | REPLYLIMIT NUMBER { portset.apcstat_replylimit = $2; }
+                | REQUESTLIMIT NUMBER { portset.apcstat_requestlimit = $2; }
+                | STARTLIMIT NUMBER { portset.apcstat_startlimit = $2; }
+                | WAITLIMIT NUMBER { portset.apcstat_waitlimit = $2; }
+                | GRACEFULLIMIT NUMBER { portset.apcstat_gracefullimit = $2; }
+                | CLEANUPLIMIT NUMBER { portset.apcstat_cleanuplimit = $2; }
+                ;
+
 nettimeout      : /* EMPTY */ {
                    $<number>$= NET_TIMEOUT;
                   }
@@ -1567,6 +1599,16 @@
   p->pathname= pp->pathname;
   p->hostname= pp->hostname;
   p->request_checksum= pp->request_checksum;
+  p->ApacheStatus.loglimit= pp->apcstat_loglimit;
+  p->ApacheStatus.closelimit= pp->apcstat_closelimit;
+  p->ApacheStatus.dnslimit= pp->apcstat_dnslimit;
+  p->ApacheStatus.keepalivelimit= pp->apcstat_keepalivelimit;
+  p->ApacheStatus.replylimit= pp->apcstat_replylimit;
+  p->ApacheStatus.requestlimit= pp->apcstat_requestlimit;
+  p->ApacheStatus.startlimit= pp->apcstat_startlimit;
+  p->ApacheStatus.waitlimit= pp->apcstat_waitlimit;
+  p->ApacheStatus.gracefullimit= pp->apcstat_gracefullimit;
+  p->ApacheStatus.cleanuplimit= pp->apcstat_cleanuplimit;
 
   if (p->request_checksum) {
     cleanup_hash_string(p->request_checksum);
@@ -1929,6 +1971,7 @@
 
   switch (protocol) {
   case P_HTTP:    return create_http();
+  case P_APACHESTATUS:  return create_apache_status();
   case P_FTP:     return create_ftp();
   case P_SMTP:    return create_smtp();
   case P_POP:     return create_pop();
@@ -2462,6 +2505,16 @@
   portset.sslversion= SSL_VERSION_AUTO;
   portset.request= NULL;
   portset.request_checksum= NULL;
+  portset.apcstat_loglimit= 0;
+  portset.apcstat_closelimit= 0;
+  portset.apcstat_dnslimit= 0;
+  portset.apcstat_keepalivelimit= 0;
+  portset.apcstat_replylimit= 0;
+  portset.apcstat_requestlimit= 0;
+  portset.apcstat_startlimit= 0;
+  portset.apcstat_waitlimit= 0;
+  portset.apcstat_gracefullimit= 0;
+  portset.apcstat_cleanuplimit= 0;
   portset.generic= NULL;
   portset.protocol= NULL;
   portset.pathname= NULL;
diff -Naur monit-4.4/protocols/apache_status.c 
monit-4.4-patched/protocols/apache_status.c
--- monit-4.4/protocols/apache_status.c 1970-01-01 01:00:00.000000000 +0100
+++ monit-4.4-patched/protocols/apache_status.c 2004-12-09 23:51:16.000000000 
+0000
@@ -0,0 +1,315 @@
+/*
+ * Copyright (C), 2000-2004 by the monit project group.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <config.h>
+
+#ifdef HAVE_STDIO_H
+#include <stdio.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#include "protocol.h"
+
+#undef   READ_SIZE
+#define  READ_SIZE  8192
+
+/* Private prototypes */
+static int check_apache_stat(Socket_T s);
+
+/**
+ * Check an Apache server to monitor its status.
+ * Do this using the server-status report from mod_status, which 
+ * will only be available if the server is responding to 
+ * some extent.
+ * Currently based on the Scoreboard response, which is available
+ * even with ExtendedStatus Off on Apache config file.
+ * 
+ */
+int check_apache_status(Socket_T s) {
+
+  char host[STRLEN];
+  char *request= NULL;
+
+  ASSERT(s);
+
+  request= "/server-status?auto";
+ 
+  if(socket_print(s, "GET %s HTTP/1.1\r\n"
+                 "Host: %s\r\n"
+                 "Accept: */*\r\n"
+                 "User-Agent: %s/%s\r\n"
+                 "Connection: close\r\n\r\n",
+                 request, get_host_header(s, host, STRLEN), prog, VERSION) < 
0) {
+    log("HTTP: error sending data -- %s\n", STRERROR);
+    return FALSE;
+  }
+
+  return check_apache_stat(s);  
+}
+
+
+/* ----------------------------------------------------------------- Private */
+
+
+/**
+ * Extract the Scoreboard line from the mod_status response.
+ * Count the active apache child processes, and those which are
+ * in other states. If each percentage exceeds the corresponding
+ * limit, then return FALSE.
+ * @param s A socket
+ * @param limit The maximum percentage of logging processes
+ * @return TRUE if logging is OK otherwise FALSE
+ */
+static int check_apache_stat(Socket_T s) {
+  
+  char line[STRLEN];
+  char search_string[STRLEN];
+  int scored = 0;
+  int tests = 0;
+  int errors = 0;
+
+  int loglimit= 0;
+  int closelimit= 0;
+  int dnslimit= 0;
+  int keepalivelimit= 0;
+  int replylimit= 0;
+  int requestlimit= 0;
+  int startlimit= 0;
+  int waitlimit= 0;
+  int gracefullimit= 0;
+  int cleanuplimit= 0;
+  
+  int no_logging = 0;
+  int no_close = 0;
+  int no_dns = 0;
+  int no_keepalive = 0;
+  int no_reply = 0;
+  int no_request = 0;
+  int no_start = 0;
+  int no_wait = 0;
+  int no_graceful = 0;
+  int no_cleanup = 0;
+  int active_servers = 0;
+  char *p;
+
+  if(socket_get_Port(s)) {
+    loglimit= ((Port_T)(socket_get_Port(s)))->ApacheStatus.loglimit;
+    closelimit= ((Port_T)(socket_get_Port(s)))->ApacheStatus.closelimit;
+    dnslimit= ((Port_T)(socket_get_Port(s)))->ApacheStatus.dnslimit;
+    keepalivelimit= 
((Port_T)(socket_get_Port(s)))->ApacheStatus.keepalivelimit;
+    replylimit= ((Port_T)(socket_get_Port(s)))->ApacheStatus.replylimit;
+    requestlimit= ((Port_T)(socket_get_Port(s)))->ApacheStatus.requestlimit;
+    startlimit= ((Port_T)(socket_get_Port(s)))->ApacheStatus.startlimit;
+    waitlimit= ((Port_T)(socket_get_Port(s)))->ApacheStatus.waitlimit;
+    gracefullimit= ((Port_T)(socket_get_Port(s)))->ApacheStatus.gracefullimit;
+    cleanuplimit= ((Port_T)(socket_get_Port(s)))->ApacheStatus.cleanuplimit;
+  }
+
+  while(NULL != socket_readln(s, line, STRLEN)) {
+    if(starts_with(line, "Scoreboard")) {   
+      if(1 != sscanf(line, "%*s%*[: ]%s", search_string)) {
+       chomp(line, STRLEN);
+       log("APACHE-STATUS error: parsing Apache status response '%s'\n", line);
+       return FALSE;
+      }else{
+        scored = 1;
+      }
+    }
+  }
+  
+  DEBUG("Scoreboard: %s\n", search_string);
+  
+  /*Check that some scoreboard line was found, if not return an error*/
+  if(!scored){
+    log("APACHE-STATUS error: no scoreboard line returned by Apache\n");
+    return FALSE;
+  }
+  
+  /* Total each of the status messages in the scoreboard */
+  for(p = search_string ; *p ; p++){
+    active_servers++;
+    switch(*p){
+    case 'S':
+      no_start++;
+      break;
+    case 'R':
+      no_request++;
+      break;
+    case 'W':
+      no_reply++;
+      break;
+    case 'K':
+      no_keepalive++;
+      break;
+    case 'D':
+      no_dns++;
+      break;
+    case 'C':
+      no_close++;
+      break;
+    case 'L':
+      no_logging++;
+      break;
+    case 'G':
+      no_graceful++;
+      break;
+    case 'I':
+      no_cleanup++;
+      break;
+    case '_':
+      no_wait++;
+      break;
+    case '.':
+      active_servers--;
+      break;
+    }
+  }
+
+  if(active_servers <= 0){
+    log("APACHE-STATUS error: No active servers found\n");
+    return FALSE;
+  }
+
+  /* Conditions are only tested if the limit parameter is greater than zero. */
+  
+  if( loglimit > 0 ){
+    tests++;
+    if((100 * no_logging / active_servers) > loglimit){
+      log("APACHE-STATUS error: "
+          "more than %i percent of Apache processes are logging\n", loglimit);
+      errors++;
+    }
+  }
+
+  if( startlimit > 0 ){
+    tests++;
+    if((100 * no_start / active_servers) > startlimit){
+      log("APACHE-STATUS error: "
+          "more than %i percent of Apache processes "
+          "are starting\n", startlimit);
+      errors++;
+    }
+  }
+
+  if( requestlimit > 0 ){
+    tests++;
+    if((100 * no_request / active_servers) > requestlimit){
+      log("APACHE-STATUS error: "
+          "more than %i percent of Apache processes "
+          "are reading requests\n", requestlimit);
+      errors++;
+    }
+  }
+
+  if( replylimit > 0  ){
+    tests++;
+    if((100 * no_reply / active_servers) > replylimit){
+      log("APACHE-STATUS error: "
+          "more than %i percent of Apache processes "
+          "are sending a reply\n", replylimit);
+      errors++;
+    }
+  }
+
+  if( keepalivelimit > 0 ){
+    tests++;
+    if((100 * no_keepalive / active_servers) > keepalivelimit){
+      log("APACHE-STATUS error: more than %i percent of Apache "
+          "processes are in keepalive\n", keepalivelimit);
+      errors++;
+    }
+  }
+
+  if( dnslimit > 0 ){
+    tests++;
+    if((100 * no_dns / active_servers) > dnslimit){
+      log("APACHE-STATUS error: more than %i percent of Apache "
+          "processes are waiting for DNS\n", dnslimit);
+      errors++;
+    }
+  }
+
+  if( closelimit > 0 ){
+    tests++;
+    if((100 * no_close / active_servers) > closelimit){
+      log("APACHE-STATUS error: more than %i percent of Apache "
+          "processes are closing connections\n", closelimit);
+      errors++;
+    }
+  }
+
+  if( gracefullimit > 0 ){
+    tests++;
+    if ((100 * no_graceful / active_servers) > gracefullimit){
+      log("APACHE-STATUS error: more than %i percent of Apache "
+          "processes are finishing gracefully\n", gracefullimit);
+      errors++;
+    }
+  }
+
+  if( cleanuplimit > 0 ){
+    tests++;
+    if((100 * no_cleanup / active_servers) > cleanuplimit){
+      log("APACHE-STATUS error: more than %i percent of Apache "
+          "processes are in idle cleanup\n", cleanuplimit);
+      errors++;
+    }
+  }
+
+  if( waitlimit > 0 ){
+    tests++;
+    if((100 * no_wait / active_servers) < waitlimit){
+      log("APACHE-STATUS error: less than %i percent of Apache processes "
+          "are waiting for a connection\n", waitlimit);
+      errors++;
+    }
+  }
+
+  /* If no tests have been made then return false, and give an error */
+  if(tests == 0){
+    log("APACHE-STATUS error: no tests could be perforemed\n");
+    return FALSE;
+  }
+
+  /* Single and multple tests return here, if all are failed */
+  if(errors == tests)
+    return FALSE;
+  
+  /* Single test passed, or multiple tests but not all failed */
+  return TRUE;
+}
diff -Naur monit-4.4/protocols/http.c monit-4.4-patched/protocols/http.c
--- monit-4.4/protocols/http.c  2004-02-25 14:50:56.000000000 +0000
+++ monit-4.4-patched/protocols/http.c  2004-12-08 19:19:14.000000000 +0000
@@ -43,10 +43,6 @@
 #include <netinet/in.h>
 #endif
 
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
 #include "../md5.h"
 #include "../sha.h"
 #include "protocol.h"
@@ -58,7 +54,6 @@
 
 /* Private prototypes */
 static int check_request(Socket_T s);
-static char *get_host_header(Socket_T s, char * host);
 static int check_request_checksum(Socket_T s, char *checksum, int);
 
 
@@ -105,7 +100,7 @@
                  "Accept: */*\r\n"
                  "User-Agent: %s/%s\r\n"
                  "Connection: close\r\n\r\n",
-                 request, get_host_header(s, host), prog, VERSION) < 0) {
+                 request, get_host_header(s, host,STRLEN), prog, VERSION) < 0) 
{
     log("HTTP: error sending data -- %s\n", STRERROR);
     return FALSE;
   }
@@ -123,30 +118,6 @@
 
 
 /**
- * @return a "hostname:port" or a void string if host
- * equals LOCALHOST or if it is an IP address
- */
-static char *get_host_header(Socket_T s, char *hostbuf) {
-
-  if(! strcmp(LOCALHOST, socket_get_remote_host(s)) ||
-     inet_aton(socket_get_remote_host(s), NULL)) {
-
-    *hostbuf= 0;
-
-  } else {
-
-    snprintf(hostbuf, STRLEN, "%s:%d",
-            socket_get_remote_host(s),
-            socket_get_remote_port(s));
-    
-  }
-
-  return hostbuf;
-
-}
-
-
-/**
  * Check that the server returns a valid HTTP response
  * @param s A socket
  * @return TRUE if the respons is valid otherwise FALSE
diff -Naur monit-4.4/protocols/protocol.c monit-4.4-patched/protocols/protocol.c
--- monit-4.4/protocols/protocol.c      2004-01-29 17:52:12.000000000 +0000
+++ monit-4.4-patched/protocols/protocol.c      2004-12-08 21:21:53.000000000 
+0000
@@ -36,6 +36,7 @@
 /* Private variables */
 static Protocol_T mydefault= NULL;
 static Protocol_T myhttp= NULL;
+static Protocol_T myapache_status= NULL;
 static Protocol_T myftp= NULL;
 static Protocol_T mysmtp= NULL;
 static Protocol_T mypop= NULL;
@@ -81,6 +82,7 @@
   FREE(myrdate);   
   FREE(myrsync);   
   FREE(mygeneric); 
+  FREE(myapache_status);
 
 }
 
@@ -111,6 +113,19 @@
 }
 
 
+void *create_apache_status() {
+
+  if(myapache_status == NULL) {
+    NEW(myapache_status);
+    myapache_status->name= "APACHESTATUS";
+    myapache_status->check= check_apache_status;
+  }
+
+  return myapache_status;
+
+}
+
+
 void *create_ftp() {
 
   if(myftp == NULL) {
diff -Naur monit-4.4/protocols/protocol.h monit-4.4-patched/protocols/protocol.h
--- monit-4.4/protocols/protocol.h      2004-01-29 17:52:12.000000000 +0000
+++ monit-4.4-patched/protocols/protocol.h      2004-12-08 21:18:42.000000000 
+0000
@@ -41,11 +41,13 @@
 #define P_RDATE    12
 #define P_RSYNC    13
 #define P_GENERIC  14
+#define P_APACHESTATUS   15
 
 /* Protocol Factory routines */
 void  gc_protocols();
 void* create_default();
 void* create_http();
+void* create_apache_status();
 void* create_ftp();
 void* create_smtp();
 void* create_pop();
@@ -66,6 +68,7 @@
 int check_pop(Socket_T);
 int check_ftp(Socket_T);
 int check_http(Socket_T);
+int check_apache_status(Socket_T);
 int check_smtp(Socket_T);
 int check_imap(Socket_T);
 int check_nntp(Socket_T);
diff -Naur monit-4.4/util.c monit-4.4-patched/util.c
--- monit-4.4/util.c    2004-08-18 20:09:00.000000000 +0100
+++ monit-4.4-patched/util.c    2004-12-08 19:19:10.000000000 +0000
@@ -86,6 +86,10 @@
 #include <crypt.h>
 #endif
 
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+
 #include "monitor.h"
 #include "engine.h"
 #include "md5.h"
@@ -1585,6 +1589,28 @@
 
 }
 
+/**
+ * @return a "hostname:port" or a void string if host
+ * equals LOCALHOST or if it is an IP address
+ */
+char *get_host_header(Socket_T s, char *hostbuf, int len) {
+
+  if(! strcmp(LOCALHOST, socket_get_remote_host(s)) ||
+     inet_aton(socket_get_remote_host(s), NULL)) {
+
+    *hostbuf= 0;
+
+  } else {
+
+    snprintf(hostbuf, len, "%s:%d",
+            socket_get_remote_host(s),
+            socket_get_remote_port(s));
+    
+  }
+
+  return hostbuf;
+
+}
 
 /* ----------------------------------------------------------------- Private */
 


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2) Documentation patch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- ./monit_orig.pod    2004-12-08 21:05:44.000000000 +0000
+++ ./monit.pod 2004-12-10 00:46:45.000000000 +0000
@@ -1570,6 +1570,40 @@
 the moment only the HTTP protocol supports the request option.
 See also below for an example.
 
+In addition to the standard protocols, the I<APACHE-STATUS> 
+protocol is a test of a specific server type, rather than a 
+generic protocol. Server performance is examined using the status
+page generated by Apache's mod_status, which is expected to be at
+its default address of http://www.example.com/server-status. 
+Currently the I<APACHE-STATUS> protocol examines the percentage 
+of Apache child processes which are 
+
+ o logging (loglimit)
+ o closing connections (closelimit)
+ o performing DNS lookups (dnslimit)
+ o in keepalive with a client (keepalivelimit)
+ o replying to a client (replylimit)
+ o receiving a request (requestlimit)
+ o initialising (startlimit)
+ o waiting for incoming connections (waitlimit)
+ o gracefully closing down (gracefullimit)
+ o performing cleanup procedures (cleanuplimit)
+
+For each of these quantities a percentage limit relative to the
+total number of active Apache child processes can be set as an
+action trigger. For waiting clients, action is taken if the 
+percentage of available clients drops below the percentage limit.
+For all the other monitored quantities, the action is taken when
+the monitored percentage rises above the limit.
+
+The codes in brackets above are used in the I<APACHE-STATUS>
+protocol statement as shown below in an example using a 
+"loglimit" of 10 percent of processes. Further examples are 
+below.
+
+ [PROTO(COL) apache-status loglimit 10 
+
+
 B<send/expect: {SEND|EXPECT} "string" ...>.  If monit does not
 support the protocol spoken by the server, you can write your own
 protocol-test using I<send> and I<expect> strings. The I<SEND>
@@ -2655,6 +2689,25 @@
           expect "HTTP/[0-9\.]{3} 200 .*\r\n"
           then alert 
 
+To make sure that Apache is logging successfully (i.e. no more 
+than 60 percent of child servers are logging), use its mod_status
+page at www.sol.no/server-status with this special protocol test:
+
+ check process apache with pidfile /var/run/httpd.pid
+       start "/etc/init.d/httpd start"
+       stop  "/etc/init.d/httpd stop"
+       if failed host www.sol.no port 80
+       protocol APACHE-STATUS loglimit 60 then restart
+
+This configuration can be used to alert you if 25 percent or more
+of Apache child processes are stuck performing DNS lookups:
+
+ check process apache with pidfile /var/run/httpd.pid
+       start "/etc/init.d/httpd start"
+       stop  "/etc/init.d/httpd stop"
+       if failed host www.sol.no port 80
+       protocol APACHE-STATUS dnslimit 25 then alert
+
 Here we use an icmp ping test to check if a remote host is up and
 if not send an alert:
 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- 
---------------------------------------
Email address@hidden
---------------------------------------




reply via email to

[Prev in Thread] Current Thread [Next in Thread]