10 01 2013
Fix for Blank Graphs using Percona Cacti Monitoring Plugins with Redis and Memcached
I use Cacti to monitor my servers and recently had some trouble getting the percona graphs to work with memcached and redis on a remote debian server. The graphs were always blank. I’m going to provide a few fixes to ss_get_by_ssh.php in this post that I used to make it work.
Fixing Blank Memcached Graph
Open ss_get_by_ssh.php and go to line 1060 and find this code:
1 2 3 4 5 6 |
function memcached_cmdline ( $options ) { global $memcache_port, $nc_cmd; $srv = isset($options['server']) ? $options['server'] : $options['host']; $prt = isset($options['port2']) ? $options['port2'] : $memcache_port; return "echo \"stats\nquit\" | $nc_cmd $srv $prt"; } |
This is the command that returns your current memcached stats. This would not run on debian for me. If you are getting blank graphs, open a shell to your server and run this command to see if it’s returning valid data. In this example memcached is running on 127.0.0.1 on port 11211.
1 |
echo "stats\nquit" | nc 127.0.0.1 11211 |
If my case, (ubuntu/debian), it wasn’t and this is why the graphs are blank. I had to add the -e flag to echo
1 |
echo -e "stats\nquit" | nc 127.0.0.1 11211 |
There is also a variable called $nc_cmd at the top of this file that specifies the netcat (nc) command to run, I found that I do not need the additional nc parameters so I changed it to
1 |
$nc_cmd = 'nc'; |
Here is my modified function, I replaced the old code with this (added the -e flag to echo).
1 2 3 4 5 6 |
function memcached_cmdline ( $options ) { global $memcache_port, $nc_cmd; $srv = isset($options['server']) ? $options['server'] : $options['host']; $prt = isset($options['port2']) ? $options['port2'] : $memcache_port; return "echo -e \"stats\nquit\" | $nc_cmd $srv $prt"; } |
You can use this command on your cacti server to test this now:
1 |
su - CACTIUSER -c 'env -i php PATH/TO/ss_get_by_ssh.php --host IPADDRESS --type memcached --items h6,h7' |
These scripts connect to the machine designated by IPADDRESS and return info for a memcached server listening on localhost. CACTIUSER is the user your cron jobs run under. Check out these links for more information:
Fixing Blank Redis Graph
Go to line 1243 of ss_get_by_ssh.php and completely delete the function redis_get(). You must do this because in this script this is known as the $getting_func (see line 256) and takes precendence over the $cmdline_func which is this case is redis_cmdline (see line 1217). In my installation redis doesn’t respond at all when using netcat. I replaced netcat with a call to redis-cli which is the built in cli tool for redis.
Replace the existing redis_cmdline at line 127 with this much simpler function:
1 2 3 4 |
function redis_cmdline ( $options ) { global $redis_port, $status_server; return "redis-cli info"; } |
This will simply called redis-cli on the remote machine and return the info. If you require more custom options, you should be able to customize this method.
Here is a simple way to test that it is working:
1 |
su - CACTIUSER -c 'env -i php PATH/TO/ss_get_by_ssh.php --host IPADDRESS --type redis --items iy,iz,j2,j3' |
Hope this helps.
Invalidating the Result Cache in Doctrine & Symfony2 Remove dark colors/scrollbars from Cinnamon Adwaita theme