Permalink
Browse files

Adds memcached_cache plugin to show the volume of cache hits and misses

  • Loading branch information...
aaronpk committed Jul 10, 2011
1 parent e9d5515 commit fe882e5b09e7f04df29281c842679bb08d4c511a
Showing with 39 additions and 0 deletions.
  1. +39 −0 memcached_cache.php
View
@@ -0,0 +1,39 @@
+#!/usr/bin/php
+<?php
+
+$mode = array_key_exists(1, $argv) ? $argv[1] : '';
+
+$host = array_key_exists('host', $_SERVER) ? $_SERVER['host'] : 'localhost';
+$port = array_key_exists('port', $_SERVER) ? $_SERVER['port'] : '11211';
+
+$stats = shell_exec('echo "stats" | nc ' . $host . ' ' . $port . ' | grep "get_hits\|get_misses\|delete_hits\|delete_misses"');
+$lines = explode("\n", $stats);
+$stats = array();
+foreach($lines as $l)
+ if(trim($l) != '')
+ $stats[] = explode(' ', $l);
+
+if($mode == 'config')
+{
+ echo 'graph_title Memcached - Cache Info' . "\n";
+ echo 'graph_info Shows the volume of cache hits and misses' . "\n";
+ echo 'graph_vlabel /second' . "\n";
+ echo 'graph_category memcache' . "\n";
+ echo 'graph_args --lower-limit 0' . "\n";
+ echo 'graph_scale yes' . "\n";
+ $first = TRUE;
+echo 'get_hits.label get_hits
+get_hits.type COUNTER
+get_hits.draw AREA
+get_misses.label get_misses
+get_misses.type COUNTER
+get_misses.draw STACK
+';
+}
+else
+{
+ foreach($stats as $s)
+ {
+ echo $s[1] . '.value ' . $s[2] . "\n";
+ }
+}

0 comments on commit fe882e5

Please sign in to comment.