Index: memcache.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/memcache/memcache.module,v
retrieving revision 1.3
diff -u -r1.3 memcache.module
--- memcache.module	12 Jan 2007 22:19:52 -0000	1.3
+++ memcache.module	3 Apr 2007 22:20:16 -0000
@@ -36,3 +36,67 @@
     dmemcache_delete($node->nid, 'node');
   }
 }
+
+/**
+ * Implementation of hook_menu().
+ */
+function memcache_menu($may_cache) {
+  $items = array();
+  if ($may_cache) {
+    $items[] = array(
+      'path' => 'admin/logs/memcache',
+      'title' => t('Memcache status'),
+      'description' => t('Get a status report on memcache performance.'),
+      'callback' => 'memcache_status',
+      'weight' => 10,
+      'access' => user_access('administer site configuration'));
+  }
+  return $items;
+}
+
+/**
+ * Menu callback. Generate a page of information about the update status of memcache.
+ */
+function memcache_status() {
+  $memcache = new Memcache;
+  $memcache_servers = variable_get('memcache_servers', array('default' => array('localhost' => array(11211))));
+  foreach ($memcache_servers as $cell => $servers) {
+    foreach ($servers as $host => $ports) {
+      foreach ($ports as $port) {
+        $memcache->addServer($host, $port);
+      }
+    }
+  }
+  return theme('memcache_report', $memcache->getExtendedStats());
+}
+
+/**
+ * Theme memcache status report. $data is the results from $memcache->getExtendedStats()
+ * See http://au.php.net/manual/en/function.Memcache-getExtendedStats.php
+ */
+function theme_memcache_report($data) {
+  $output = '<p>Simple Memcache Status</p>';
+
+  // until we create a nice UI for this, just dump the values in a bunch of tables
+  $header = array(
+    'Attribute',
+    'Value'
+  );
+
+  foreach ($data as $hostport => $values) {
+    $output.= '<h2>' . $hostport . '</h2>';
+    if (is_array($values)) {
+      foreach ($values as $key => $value) {
+        $row = array();
+        $row['data'][] = array('class' => 'attribute', 'data' => $key);
+        $row['data'][] = array('class' => 'value', 'data' => $value);
+        $rows[] = $row;
+      }
+      $output .= theme('table', $header, $rows, array('class' => 'memcache-status'));
+    } else {
+      $output .= '<p>ERROR: could not fetch statistics</p>';
+    }
+  }
+
+  return $output;
+}
