You are here

function memcache_admin_stats in Memcache API and Integration 5

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

Memcahe Stats page

Parameters

string $cluster - which cluster to view?:

string $type - which type of stat, eg: default, reset, malloc, maps, cachedump, slabs, items or sizes:

Return value

string

1 string reference to 'memcache_admin_stats'
memcache_admin_menu in memcache_admin/memcache_admin.module
Implementation of hook_menu

File

memcache_admin/memcache_admin.module, line 124

Code

function memcache_admin_stats($cluster = 'default', $type = 'default') {
  $bin = _memcache_admin_get_bin_for_cluster($cluster);
  if ($bin) {
    $stats = dmemcache_stats($bin, $type);
    if (is_array($stats) && count($stats)) {
      $output = "";
      foreach ($stats as $server => $values) {
        if (is_array($values)) {

          //Do some custome value tweaks for specific stat page types.
          switch ($type) {
            case 'default':
              $values['uptime'] = format_interval($values['uptime']);
              $values['time'] = format_date($values['time']);
              $values['bytes'] = format_size($values['bytes']);
              $values['bytes_read'] = format_size($values['bytes_read']);
              $values['bytes_written'] = format_size($values['bytes_written']);
              $values['limit_maxbytes'] = format_size($values['limit_maxbytes']);

              //Custom Entries
              $values['hit_percentage'] = $values['cmd_get'] > 0 ? number_format(100.0 * $values['get_hits'] / $values['cmd_get'], 2) . '%' : '0';
              $mem_used = intval($values['bytes']) / (intval($values['limit_maxbytes']) * 1024);
              $values['mem_used'] = number_format(100.0 * $mem_used, 2) . '%';
              break;
          }
          $output .= theme('memcache_admin_stats_table', $server, $values);
        }
        else {
          drupal_set_message(t('Unable to connect to server: %server', array(
            '%server' => $server,
          )));
        }
      }
    }
    else {
      $output = '';
      drupal_set_message(t('No available statistics for this bin.'));
    }
  }
  return $output;
}