Atom Feed
Comments Atom Feed

Similar Articles

2016-03-12 15:33
PHP Zend opcache on Cacti via SNMP
2015-01-08 22:58
Nginx on Cacti via SNMP
2015-01-08 22:59
php-fpm on Cacti via SNMP
2009-11-14 13:46
Apache stats on Cacti (via SNMP)
2010-03-20 21:52
apcupsd stats 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

PHP APC on Cacti via SNMP

For a while now I've had a task on my list to "blog up Cacti APC". This is of course referring to the popular APC opcode cache for PHP. Monitoring the opcode cache is very important for PHP since if it is not working efficiently (eg. many evictions due to lack of memory) then PHP is going to be burning a lot of resource on continually recompiling code.

At some point I'll do the same for the Zend cache, but for now here's what I've done for APC.

Before attempting this, look at my previous article on SNMP basics takes look at general setup of snmpd and how basic extensions work.

Extracting the statistics

There is no built-in monitoring hook in APC, but instead the PHP function apc_cache_info() provides a way to extract statistics. The easiest way to do this is to have a small PHP page which extracts the statistics we want. For this I've written one that outputs a plain-text list of statistics.

Download: PHP APC monitoring scripts and Cacti Templates on GitHub

The monitoring script apcstat.php can be put somewhere it can be served by the webserver you are using with PHP. For example the configuration for Nginx with php-fpm for this placed in the root of a web site would be:

        location /apcstat.php {
                access_log off;
                allow ::1;
                deny all;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                root /path/to/root/of/site/;
                include fastcgi_params;

Then to pick the data up via snmpd, add the following lines to /etc/snmp/snmpd.conf to call the script for appropriate SNMP requests:

# php apc
extend phpapc /usr/bin/curl --silent http://localhost/apcstat.php

Restart snmpd and you should be able to get basic stats via SNMP.

Cacti Templates

I have generated some basic Cacti Templates for APC.

Simply import the template cacti_host_template_php_apc.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

From an extremely lightweight site...

Cacti PHP APC Cache Efficiency

Cacti PHP APC Cache Usage