Menu
Index

Contact
Atom Feed
Comments Atom Feed

Similar Articles

2015-01-08 22:59
php-fpm on Cacti via SNMP
2015-05-14 22:35
PHP APC on Cacti via SNMP
2016-03-12 15:33
PHP Zend opcache on Cacti via SNMP
2015-01-08 22:58
Nginx on Cacti via SNMP
2015-02-13 22:51
opendkim on Cacti via SNMP

Recent Articles

2019-07-28 16:35
git http with Nginx via Flask wsgi application (git4nginx)
2018-05-15 16:48
Raspberry Pi Camera, IR Lights and more
2017-04-23 14:21
Raspberry Pi SD Card Test
2017-04-07 10:54
DNS Firewall (blackhole malicious, like Pi-hole) with bind9
2017-03-28 13:07
Kubernetes to learn Part 4

Glen Pitt-Pladdy :: Blog

Apache stats on Cacti (via SNMP)

Following on from the basics of SNMP I did previously, this article now adds my next set of SNMP extension scripts, config, and Cacti templates to monitor an Apache web server.

Apache Stats

Apache fortunately generates comprehensive stats internally and presents it under the url http://localhost/server-status?auto in a form that is easily parsable by scripts. All that is needed is to extract the stats.

Because a number of hits on the server will be needed for each statistic when snmpd is queried, it is a good idea to do some basic caching so that the stats retreval doesn't become the dominant load on an otherwise lightly loaded server.

The one thing that needs to be changed in Apache's config is to switch to extended stats. On Debian and Ubuntu systems edit the file /etc/apache2/mods-available/status.conf and add the directive "ExtendedStatus on" just before the Location section. Reload apache and it should be ready to go.

Getting Apache stats over SNMP

As the stats are available to the local machine (localhost or 127.0.0.1) over http, we once again avoid acrobatics discussed previously needed to get some data into snmpd. A single extension script is all that is needed.

To allow caching, I have created an additional directory: /var/local/snmp/cache

Set this to be owned by snmp so that it can write and modify files in here: chown snmp: /var/local/snmp/cache

Download: Apache statistics SNMP scripts and Cacti Templates are on GitHub

There is a choice between a Python script apache-stats.py and a Shell script apache-stats.sh. The shell script is likely to have more overhead due to spinning up a load of processes each time it gets hit. With Python you will also need the python3-requests package (or at least that's what it's called in Debian / Ubuntu), and with the Shell option you will need wget.

I place this script (make it executable first: chmod +x apache-stats.py) in /etc/snmp

In /etc/snmp/snmpd.conf add the following line (or others if you want to monitor them):

extend apache /etc/snmp/apache-stats.py

.... or as appropriate if you are using the shell version

Once you have added all this in you can test apache-stats by running it from the command line with appropriate parameters, and via SNMP by appending the appropriate SNMP OID to the "snmpwalk" commands shown previously.

Cacti Templates

I have generated some basic Cacti Templates for these Apache stats.

Simply import the template cacti_host_template_apache.xml, and add the graphs you want to the appropriate device graphs in Cacti. It should just work if your SNMP is working correctly for that device (ensure other SNMP parameters are working for that device).

Graph Screen Shots

Apache Stats over SNMP on Cacti : Bytes per Request

Apache Stats over SNMP on Cacti : Bytes per Second

Apache Stats over SNMP on Cacti : CPU Load

Apache Stats over SNMP on Cacti : Scoreboard

Apache Stats over SNMP on Cacti : Workers

Update:

One person had pointed out that there has been some problems on some versions of Cacti with importing the templates. The template was generated with version 0.8.7b (from Debain Lenny).

The problem manifests it's self as "Cacti version does not exist" error, and appears to be cured by adding in this version, although in my version the file is actually global_arrays.php

The relevant array from my global_arrays.php / config_array.php:

$hash_version_codes = array(
    "0.8.4"  => "0000",
    "0.8.5"  => "0001",
    "0.8.5a" => "0002",
    "0.8.6"  => "0003",
    "0.8.6a" => "0004",
    "0.8.6b" => "0005",
    "0.8.6c" => "0006",
    "0.8.6d" => "0007",
    "0.8.6e" => "0008",
    "0.8.6f" => "0009",
    "0.8.6g" => "0010",
    "0.8.6h" => "0011",
    "0.8.6i" => "0012",
    "0.8.6j" => "0013",
    "0.8.7"  => "0014",
    "0.8.7a" => "0015",
    "0.8.7b" => "0016",
    "0.8.7c" => "0017",
    "0.8.7d" => "0018",
    "0.8.7e" => "0019",
    "0.8.7f" => "0020",
    "0.8.7g" => "0021"
    );