You are reading

APC Plugin For Munin

Posted: May 25, 2010 | By: TJ | In Technology | No comments yet

If you’re like me, you want to monitor and graph every little piece of your server. Until recently, I’ve been relying on a simple PHP script to display APC statistics. Although the tool worked well, I wanted to integrate the statistics into Munin, as most all other server properties and system services are monitoring with it. The problem was that finding a suitable APC plugin for Munin proved to be very difficult. Fortunately I stumbled across this German gem (Vielen Dank, dass Sie meine deutsche Freundin!) that met my needs. To set this up on your system, just follow the directions below:

First, let’s set up the apcinfo.php file in the document root of your web server and retrieve the file from a private gist:

$ cd /var/www/html
$ wget http://gist.github.com/raw/403135/8cbf9c71c5f82c2cda5af864c46f91910552e9f7/apcinfo.php

Now, make the file executable:

$ chmod +x apcinfo.php

The script itself is very simple. It simply ouputs the total cache memory, memory available and memory used:

<?php
$mem = apc_sma_info();
$mem_size = $mem['num_seg']*$mem['seg_size'];
$mem_avail= $mem['avail_mem'];
$mem_used = $mem_size-$mem_avail;
$out = array(
    'size: ' . sprintf("%.2f", $mem_size),
    'used: ' . sprintf("%.2f", $mem_used),
    'free: ' . sprintf("%.2f", $mem_avail)
    );

echo implode(' ', $out);

To confirm that the script is working, check out /apcinfo.php on your site. You should see something like the following:

size: 31457200.00 used: 19478104.00 free: 11979096.00

Now, let’s set up the Munin plugin that will use that information:

$ cd /usr/share/munin/plugins
$ wget http://gist.github.com/raw/403127/51c7bf078d2ffd5b70da8b2380881648b3cc3481/apc
$ chmod +x apc
$ ln -s /usr/share/munin/plugins/apc /etc/munin/plugins/apc

What that does is create the apc plugin, makes it executable and then symlinks it to the proper directory. Now, we’ll need to make sure Munin loads the new plugin. To do this, we’ll edit the /etc/munin/plugin-conf.d/munin-node to add the following:

[apc*]
user root
env.url http://example.com/apcinfo.php

Obviously, you’ll want to replace example.com with the host you intend to use. Once the file has been updated and saved, restart Munin:

$ /etc/init.d/munin-node restart

Once the node is running, it’ll take a few minutes for Munin to update so don’t worry if you don’t see any new graphs right away. One thing to keep in mind is that you will need the LWP::UserAgent Perl module. If you are on a Debian/Ubuntu OS, just run the following to install it:

$ aptitude install libwww-perl

Now, go check your pretty graphs:

What an interesting graph!

What an interesting graph!

Comments for this entry

How do you know if its using memcache rather than files?

How do you know if its using memcache rather than files? When I set the session save path and the other part of it, it asks me to download the files. What’s wrong?

The easiest way is to tail the memcached.log. If you’ve set up verbose logging, you can watch the sessions being logged as they happen. Using something like:

$ tail -f /var/log/memecached.log

Karan

Thanks for the article, however, I get the following error when i try to run the make command: http://pastie.org/private/ndnoqi2defntxouhshtona

Any ideas? Thanks again :)

[...] is a rehash of this tutorial but for Debian [...]

[...] http://longvnit.com/blog/?p=627 http://constantshift.com/installing-apc-for-php-5-3/ CentOS 5 – PHP SSH2CentOS – soporte PHP FFMPEGCentOS 5 – Php Zend y Sql [...]

Leave your comment



Copyright © 2010. All rights reserved.

This blog is powered by WordPress and proudly hosted by (mt) Media Temple.