Snert . Com - Software - mod_watch/2.4 for Apache 1.3 & MRTG
Description: An Apache module that monitors the number of bytes passed to and from a virtual host or local user. Intended for use with MRTG.
Keywords: Apache module,mod_watch,MRTG

|  | mod_watch/2.4 from Snert . Com |
  > ## Monitoring Interface for Apache 1.3 & MRTG Daily Average Graph www.snert.com | apache2mrtg.pl | mod_watch | mod_watch.pl | | Welcome | Software | ### Description This module will watch and collect the bytes in & out per virtual host, per file owner, and the web server as a whole. This module was designed for use with MRTG, which will make nice graphical representations of the data, but is general enough that it can be applied to other purposes. ### Configuration The directives below can be added to the general Apache configuration file, `httpd.conf`. SetHandler watch-info Context: server This handler is used to display a line of plain text containing the following space separated fields: `ifName ifUptime ifInOctets ifOutOctets ifRequests ifDocuments` The `ifName` is the target name of the request made in a URL. The remaining fields are all numerical. `ifUptime` is the web server's uptime in seconds. The following is required in an httpd.conf file in order for mod_watch.pl to function (without change):
  >     <Location /watch-info>
  >     SetHandler watch-info
  >     </Location>

  >     <Location /~*/watch-info>
  >     SetHandler watch-info
  >     </Location>
  > This will permit the following URL forms to get the virtual-host, file-owner, and SERVER data respectively: http://www.snert.com/watch-info http://www.snert.com/~achowe/watch-info http://www.snert.com/~SERVER/watch-info WatchDocuments mime-type ... Context: server A list of MIME types considered to be documents, for the purpose of counting. For example "text/html" would be considered a document, which loads page elements such as images, stylesheets, audio files, etc. which are not documents, but elements of one. An asterisk in the mime-type string will act as a wildcard for zero or more of anything. This directive will override the default list:
  > application/*word |  | application/*excel |  | application/pdf
  > application/postscript | application/rtf | text/enriched
  > text/html | text/plain | text/richtext
  > text/xml
  > WatchStore dbm [host port [dbname dbsecret]] WatchStore files [directory] Context: server The WatchStore directive specifies the perfered storage policy for maintaining the counters. The dbm storage policy take two pairs of optional arguments. The first pair are the host and port of the DBM server, which default to the local host `127.0.0.1` on port `9866`. The second pair are the dbname and dbsecret for the database to use, which default to the database name "`mod_watch`" using the secret "`public`". Each key of the DBM file is either the virtual host name, file owner user name, or the string "SERVER". When using the dbm storage policy, it will be necessary to install the dbm-server.pl script so that it started before Apache. The where and how that is done varies from platform to platform and is not specified here. The files storage policy takes an optional absolute path of a directory of where to keep the "weenie" text files. The default is `/var/spool/mod_watch`. The filename of a weenie file is either the virtual host name, file owner user name, or the string "SERVER". The files storage policy is the default storage policy used. The contents of each DBM key or weenie file is a string of ASCII text containing four space separated numerical fields:
  > Name |  | Type |  | Description
  > ifInOctets | Counter32 | bytes received from POST requests
  > ifOutOctets | Counter32 | bytes sent in response to requests
  > ifRequests | Counter32 | number of requests (raw hits) received
  > ifDocuments | Counter32 | number of documents sent
2. > When updating a set of counters, a current string is first read from the specified storage medium and parsed into their respective counters. The number of octets in and out for a request are added to the current counters, and the number of requests is incremented by one. The number of documents is incremented by one, if the response MIME type matches one of the MIME types specified for the WatchDocuments directive. The counters are converted back into a string and stored back from whence they came. The counters are allowed to roll over. The convertdbm.pl utility will convert a DBM file to weenie files and back again. To convert from a DBM file to weenie files: convertdbm.pl /var/spool/dbm-server/mod_watch /var/spool/mod_watch To convert from weenie files to a DBM file: convertdbm.pl /var/spool/mod_watch /var/spool/dbm-server/mod_watch WatchWhat item ... Context: server mod_watch, by default, will collect information for the virtual host, file owner, and the server as a whole for each request made. For performance reasons, it might not be necessary to watch all these things. Specify one or more of the following to select which items to watch: `virtual-host, file-owner, server, all` ### Download mod_watch204.tgz MRTG: Multi-Router Traffic Grapher ### Installation Unpack and install MRTG prior to installing this module. Next, to build this module as DSO library for Apache, just type:
   >     cd (path to)/mod_watch-2.4
   >     make install
   > To build as a static module into Apache:
   >     cd (path to)/apache_1.3.20
   >     ./configure \
   >         --add-module=(absoulte path to)/mod_watch-2.4/mod_watch.c \
   >         --disable-shared=watch \
   >         ... (your other configuration options) ...
   >     make install
3. > In addition to the Apache module being installed, the following scripts are copied to `/usr/local/sbin`: apache2mrtg.pl, mod_watch.pl Also the directory `/var/spool/mod_watch` is created to hold the weenie files managed by mod_watch. The following must be added to the top-level server configuration within `httpd.conf` in order for mod_watch.pl to work.
   >     <IfModule mod_watch.c>
   >       # Allows the URL used to query virtual host data:
   >       #
   >       #	http://www.snert.com/watch-info
   >       #
   >       <Location /watch-info>
   >       SetHandler watch-info
   >       </Location>

   >       # Allows the URL used to query file owner and web
   >       # server data:
   >       #
   >       #	http://www.snert.com/~achowe/watch-info
   >       #	http://www.snert.com/~SERVER/watch-info
   >       #
   >       <Location /~*/watch-info>
   >       SetHandler watch-info
   >       </Location>
   >     </IfModule>
4. > Use apache2mrtg.pl to parse the httpd.conf file to create a MRTG configuration script for all the defined virtual hosts. The output can be appended to or included in an existing `mrtg.cfg` file. There currently is no support to generate MRTG configurations for virtual hosts derived from mod_vhosts_alias or local user names.
   >     perl apache2mrtg.pl (path to)/httpd.conf >web.cfg
5. > Use this generated configuration with MRTG for a cron job that executes every 5 minutes to generate the graphs. This configuration will periodically make calls to mod_watch.pl to obtain the bytes in, out, uptime, and MRTG target name. Restart the web server:
   >     apachectl restart
-   > Once the Apache web server starts receiving requests, all the bytes received in requests (excluding headers), where a Content-Length header is defined and all the bytes sent (excluding headers) in replies are added to the current 32-bit counters and stored. If the MRTG output is propery configured, you should be able to see assorted graphs concerning data transfer rates of virtual hosts, file owners, and the web server. ### Notes List of recent changes. Sample MRTG output & configurations for: Octets In & Out The follow MRTG configuration is produced by apache2mrtg.pl: Title[www.snert.com]: www.snert.com Data Traffic Target[www.snert.com]: `/usr/local/sbin/mod_watch.pl http://www.snert.com/watch-info` MaxBytes[www.snert.com]: 1250000 PageTop[www.snert.com]: <h2>www.snert.com Data Traffic</h2> Requests & Documents The following MRTG configuration was done by hand to produce Request & Document traffic: Options[www.snert.com,req]: growright, unknaszero, perhour Title[www.snert.com,req]: www.snert.com Request &amp; Document Traffic Target[www.snert.com,req]: `/usr/local/sbin/mod_watch.pl -f ifRequests,ifDocuments http://www.snert.com/watch-info` MaxBytes[www.snert.com,req]: 1250000 PageTop[www.snert.com,req]: <h2>www.snert.com Request &amp; Document Traffic</h2> YLegend[www.snert.com,req]: Hits per Hour ShortLegend[www.snert.com,req]: H/h Legend1[www.snert.com,req]: Requests (raw hits) received per Hour Legend2[www.snert.com,req]: Documents sent per Hour Legend3[www.snert.com,req]: Maximal 5 Minute Incoming Request Traffic Legend4[www.snert.com,req]: Maximal 5 Minute Outgoing Document Traffic LegendI[www.snert.com,req]: &nbsp;Hits: LegendO[www.snert.com,req]: &nbsp;Docs: mod_watch/2.4 tested on following platforms (please email me your platform if you've made it work on something different): Debian GNU/Linux, PowerPC, Apache 1.3.19 FreeBSD 4.2, Apache 1.3.19 HP-UX 11.0, Apache 1.3.12 RedHat Linux 5.1+, Apache 1.3.17 Slackware 7.0, Apache 1.3.12 SunOS 5.7, Apache 1.3.12 This machine appear to be missing the following from <sys/file.h>:
    >     	/* Operations for the `flock' call.  */
    >     	#define LOCK_SH 1    /* Shared lock.  */
    >     	#define LOCK_EX 2    /* Exclusive lock.  */
    >     	#define LOCK_UN 8    /* Unlock.  */
Communication between Apache, the DBM server, and mod_watch.pl uses TCP sockets. The dbm-server.pl will queue a small finite number or connections, however it is possibe during heavy loads (don't ask me how heavy, because I don't know) to have failed connections, in which case the module just ignores the problem. ## License This source distribution is made freely available and there is no charge for its use, provided you retain this notice, disclaimers, author's copyright, and credits. ## Disclaimer THIS SOFTWARE IS PROVIDE "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO WAY SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | apache2mrtg.pl | mod_watch | mod_watch.pl | | Welcome | Software | Copyright 2001 by Anthony C Howe All rights reserved. light bulbs since 1 April 2001