Monitoring Alternative PHP Cache (APC) Using Cacti Graphs

Cacti Logo

Despite Zend’s OPcache being available in PHP 5.5, a lot of people – myself included – still use the tried and tested Alternative PHP Cache (APC) on older versions of PHP. Although APC tries its best to have a ‘set it and forget it’ approach with very sensible and effective defaults, if you want to get the best performance out of it then you should consider monitoring the status of the cache.

I use Cacti almost exclusively on my linux machines to monitor the status of various system processes. Despite usually having no problem finding scripts to monitor just about everything, I’ve been relatively disappointed in the availability of APC monitoring scripts for Cacti so I’ve created my own. Only requirements are wget on the server hosting Cacti (you likely already have this) and the ability for said server to access a webpage on the PHP server being monitored.

The Cacti template introduces four graphs: APC Cache Hits (%); APC File Cache Requests; APC User Cache Requests; and APC Memory Usage.

APC File Requests Graph

APC Cache Hits (%) Graph

APC Memory Usage Graph

APC User Cache Requests Graph

 

Installation

  1. Copy apc_stats.php onto the target web server running PHP & APC. Make sure that it is accessible from the server running Cacti. You may want to use .htaccess on Apache or HttpAccessModule on nginx to ensure it is only accessible from this machine.
  2. Import the templates you require into Cacti.
  3. Associate the APC graph templates with the device (click Devices on the menu to the left).
  4. Create the graphs. You will be asked for a Stats URL – this is the URL from which apc_stats.php is accessed, for example http://localhost/apc_stats.php.

 

Download “APC Cacti Templates” apc-cacti-templates.tar.gz – Downloaded 243 times – 9 kB

 

I’ve only tested this on Cacti 0.8.8a with PHP 5.3.3. and APC 3.1.9. If you wish to contribute fixes/improvements, please feel free to fork on GitHub and send a pull requests.

  • dtube

    Thank you. It works perfectly. There are other apc templates/scripts but those did not work for me because i have rewrite rule to force http to https. Yours work nicely since it uses wget.

    On the remote system that I want cacti to “wget”, I added this into my httpd.conf:

    Alias /stats “/var/www/stats”

    Order deny,allow
    Deny from all
    Options +FollowSymLinks
    # IP address of machine running cacti

    Allow from x.x.x.x