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.
- 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.
- Import the templates you require into Cacti.
- Associate the APC graph templates with the device (click Devices on the menu to the left).
- 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.
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.