You are here

function memcache_admin_menu in Memcache API and Integration 7

Same name and namespace in other branches
  1. 5.2 memcache_admin/memcache_admin.module \memcache_admin_menu()
  2. 5 memcache_admin/memcache_admin.module \memcache_admin_menu()
  3. 6 memcache_admin/memcache_admin.module \memcache_admin_menu()

Implements hook_menu().

File

memcache_admin/memcache_admin.module, line 45
For the collection and display of memcache stats.

Code

function memcache_admin_menu() {
  $items['admin/config/system/memcache'] = array(
    'title' => 'Memcache',
    'description' => 'Show or hide memcache statistics at the bottom of each page.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'memcache_admin_admin_settings',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
  );
  $items['admin/reports/memcache'] = array(
    'title' => 'Memcache statistics',
    'description' => "View statistics for all configured memcache servers.",
    'page callback' => 'memcache_admin_stats',
    'access arguments' => array(
      'access memcache statistics',
    ),
    'weight' => 1,
  );
  $memcache_servers = variable_get('memcache_servers', array(
    '127.0.0.1:11211' => 'default',
  ));
  $clusters = array();
  foreach ($memcache_servers as $server => $bin) {
    if (function_exists('dmemcache_object_cluster') && ($cluster = dmemcache_object_cluster($bin))) {
      $name = $cluster['cluster'];
      $clusters[$name]['servers'][] = $server;
      $clusters[$name]['bin'] = _memcache_admin_get_bin_for_cluster($cluster['cluster']);
    }
  }
  $count = 0;
  foreach ($clusters as $cluster => $cluster_info) {
    if ($cluster_info['bin']) {
      if (empty($current_cluster)) {
        $current_cluster = arg(3);
        if (empty($current_cluster)) {
          $current_cluster = $cluster;
        }
      }
      $items["admin/reports/memcache/{$cluster}"] = array(
        'title' => $cluster,
        'type' => $count == 0 ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
        'page callback' => 'memcache_admin_stats',
        'page arguments' => array(
          $cluster,
        ),
        'access arguments' => array(
          'access memcache statistics',
        ),
        'weight' => $count++,
      );
      foreach ($cluster_info['servers'] as $server) {
        $items["admin/reports/memcache/{$cluster}/{$server}"] = array(
          'title' => check_plain($server),
          'type' => MENU_CALLBACK,
          'page callback' => 'memcache_admin_stats_raw',
          'page arguments' => array(
            $cluster,
            $server,
          ),
          'access arguments' => array(
            'access memcache statistics',
          ),
        );
        foreach (memcache_admin_stats_types($cluster) as $type) {
          $items["admin/reports/memcache/{$cluster}/{$server}/{$type}"] = array(
            'type' => MENU_CALLBACK,
            'page callback' => 'memcache_admin_stats_raw',
            'page arguments' => array(
              $cluster,
              $server,
              $type,
            ),
            'title' => $type,
            'access arguments' => array(
              'access memcache statistics',
            ),
          );
        }
      }
    }
  }
  return $items;
}