« GNU Mailman using a Apache vhost in Gentoob2evolution blacklisted »

Zabbix and monitoring Apache - Gentoo mod_status using -D STATUS


  12:07:42 am, by   , 1161 words  
Categories: Gentoo Linux

Zabbix and monitoring Apache - Gentoo mod_status using -D STATUS

In my continuing quest to monitor everything via Zabbix, I wanted the Apache status information available from the mod_status module. I had already added the needed lines into my Zabbix conf file, but the results were not getting returned properly.

Here's what the Apache2 mod_status documentation is: http://httpd.apache.org/docs/2.0/mod/mod_status.html

I wanted this info to come from a sub-domain - and I wanted is to be very restricted, by IP address, so it would not be available to the world.

Gentoo, in its default Apache configuration file /etc/conf.d/apache2, has this:


I had assumed the INFO gave status information - wrongly. Actually, the INFO command here should not be given as an example, as this enables mod_info, which is very insecure by default and can be used to reveal secret server details - read here: http://httpd.apache.org/docs/2.2/mod/mod_info.html

For Gentoo, the correct entry for mod_status in /etc/conf.d/apache2 is "-D STATUS", as in:


So, to make that change, edit the conf.d file:

# nano /etc/conf.d/apache2

Note: where the -D PHP5 is; that is just for my server, which has PHP running - if you don't or you have other items there, leave them, and just add the "-D STATUS" part on the end.

Also, there is a parameter at the bottom of the conf file:

# The URL to your server's mod_status status page.
# Required for status and fullstatus

I'm not sure if this is necessary, but it seems to be a good thing, and makes sense to me.

Since I'm serving this up using a sub-domain, I take out the default definitions for mod_status. I'll later add this into the appropriate sub-domain vhost file.

Here's the resulting '/etc/apache2/modules.d/00_mod_status.conf' after commenting out the



# cd /etc/apache2/modules.d/
# nano 00_mod_status.conf

[lt]IfDefine STATUS[gt]
[lt]IfModule status_module[gt]
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
#[lt]Location /server-status[gt]
#       SetHandler server-status
#       Order deny,allow
#       Deny from all
#       Allow from

# ExtendedStatus controls whether Apache will generate "full" status
# information (ExtendedStatus On) or just basic information (ExtendedStatus
# Off) when the "server-status" handler is called.
ExtendedStatus On

# vim: ts=4 filetype=apache

Next, edit the sub-domain's vhost file. For this example, the domain is serverstats.example.com. So, the vhost file would be /etc/apache2/vhosts.d/serverstats_example_com_vhost.conf - into this I added the example from here: http://httpd.apache.org/docs/2.0/sections.html

# cd /etc/apache2/vhosts.d/
# nano serverstats_example_com_vhost.conf

    # use this domain for fetching the Apache server status info, used by Zabbix
    [lt]Location /server-status[gt]
        SetHandler server-status

So, the resulting vhost file would look something like:

[lt]VirtualHost *:80[gt]
    ServerName serverstats.example.com
    ServerAlias www.serverstats.example.com

    ServerAdmin serverstats@example.com

    # set up where to find the HTML files
    DocumentRoot /var/www/example.com/serverstats.example.com/htdocs

    # set the default file(s) to use as the default main index page
    DirectoryIndex index.html index.htm index.php

    # allow for .htaccess files to work, etc
    [lt]Directory /var/www/example.com/serverstats.example.com/htdocs[gt]
        AllowOverride All
        Options All
        # allow access from my IP and this servers IP only
        Order deny,allow
        Deny from all
        Allow from xxx.xxx.xxx.xxx yyy.yyy.yyy.yyy

    # set up the cgi-bin directory to execute file
    ScriptAlias /cgi-bin/ /var/www/example.com/serverstats.example.com/cgi-bin/
    [lt]Directory "/var/www/example.com/serverstats.example.com/cgi-bin/"[gt]
        AllowOverride None
        Options None
        # allow access from my IP and this servers IP only
        Order deny,allow
        Deny from all
        Allow from xxx.xxx.xxx.xxx yyy.yyy.yyy.yyy

    # set up the log files
    ErrorLog     /var/www/example.com/serverstats.example.com/logs/error_log
    CustomLog    /var/www/example.com/serverstats.example.com/logs/access_log combined

    # use this domain for fetching the Apache server status info, used by Zabbix
    [lt]Location /server-status[gt]
        SetHandler server-status


Now restart Apache - I don't think a 'reload' will be enough, as we've added parameters to the /etc/conf.d/apache2 file.

# /etc/init.d/apache2 restart

and test: http://serverstats.example.com/server-status

If that pulls up a page of information about the Apache server (and the stats will probably be low, since you restarted the server so recently), then this section is done!

Next, we work on the Zabbix configuration, to get this going.

The various checks need to be added in the Zabbix Agentd config file - I use the agentd file for all the various checks, for Zabbix 1.1.7, which is fairly outdated now. Guess I should update this software sometime soon.

# nano /etc/zabbix/zabbix_agentd.conf

and add in these lines - I forget where I picked them up, probably on the Zabbix Forums or the Gentoo Forums in a post on Zabbix (or maybe even the Gentoo Zabbix Howto at the Gentoo wiki):

UserParameter=apache.accesses,wget --quiet -O - http://serverstats.example.com/server-status?auto | head -n 9 | grep Accesses | cut -d " " -f 3
UserParameter=apache.totalkb,wget --quiet -O - http://serverstats.example.com/server-status?auto | head -n 9 | grep kBytes | cut -d " " -f 3
UserParameter=apache.cpuload,wget --quiet -O - http://serverstats.example.com/server-status?auto | head -n 9 | grep CPULoad | cut -d " " -f 2
UserParameter=apache.uptime,wget --quiet -O - http://serverstats.example.com/server-status?auto | head -n 9 | grep Uptime | cut -d " " -f 2
UserParameter=apache.reqpersec,wget --quiet -O - http://serverstats.example.com/server-status?auto | head -n 9 | grep ReqPerSec | cut -d " " -f 2
UserParameter=apache.bytespersec,wget --quiet -O - http://serverstats.example.com/server-status?auto | head -n 9 | grep BytesPerSec | cut -d " " -f 2
UserParameter=apache.bytesperrec,wget --quiet -O - http://serverstats.example.com/server-status?auto | head -n 9 | grep BytesPerReq | cut -d " " -f 2
UserParameter=apache.busywokers,wget --quiet -O - http://serverstats.example.com/server-status?auto | head -n 9 | grep BusyWorkers | cut -d " " -f 2
UserParameter=apache.idleworkers,wget --quiet -O - http://serverstats.example.com/server-status?auto | head -n 9 | grep IdleWorkers | cut -d " " -f 2

and restart the Zabbix agent service, to load in these new Apache status checks.

# /etc/init.d/zabbix-agentd restart

If Zabbix server is saying it is having issues with the new checks, look at the server logs.

The log for the Zabbix Agent service is at:

# tail -f /var/log/zabbix/zabbix_agentd.log

The log for the Zabbix server is at:

# tail -f /var/log/zabbix/zabbix_server.log

Feedback awaiting moderation

This post has 48 feedbacks awaiting moderation...

Form is loading...

June 2023
Mon Tue Wed Thu Fri Sat Sun
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
 << <   > >>
LAN / Networks related items ...


  XML Feeds

powered by b2evolution free blog software