You are here

function dmemcache_stats in Memcache API and Integration 6

Same name and namespace in other branches
  1. 5.2 dmemcache.inc \dmemcache_stats()
  2. 5 dmemcache.inc \dmemcache_stats()
  3. 7 dmemcache.inc \dmemcache_stats()
3 calls to dmemcache_stats()
memcache_admin_stats in memcache_admin/memcache_admin.module
Memcahe Stats page
memcache_admin_stats_raw in memcache_admin/memcache_admin.module
theme_memcache_admin_stats_raw_table in memcache_admin/memcache_admin.module
1 string reference to 'dmemcache_stats'
memcache_admin_requirements in memcache_admin/memcache_admin.install
Implementation of hook_requirements().

File

./dmemcache.inc, line 501

Code

function dmemcache_stats($stats_bin = 'cache', $stats_type = 'default', $aggregate = FALSE) {
  $memcache_bins = variable_get('memcache_bins', array(
    'cache' => 'default',
  ));
  if (!isset($memcache_bins['cache'])) {
    $memcache_bins['cache'] = 'default';
  }

  // The stats_type can be over-loaded with an integer slab id, if doing a
  // cachedump.  We know we're doing a cachedump if $slab is non-zero.
  $slab = (int) $stats_type;
  $stats = array();
  foreach ($memcache_bins as $bin => $target) {
    if ($stats_bin == $bin) {
      if ($mc = dmemcache_object($bin)) {
        if ($mc instanceof Memcached) {
          $stats[$bin] = $mc
            ->getStats();
        }
        else {
          if ($mc instanceof Memcache) {
            if ($stats_type == 'default' || $stats_type == '') {
              $stats[$bin] = $mc
                ->getExtendedStats();
            }
            else {
              if (!empty($slab)) {
                $stats[$bin] = $mc
                  ->getStats('cachedump', $slab);
              }
              else {
                $stats[$bin] = $mc
                  ->getExtendedStats($stats_type);
              }
            }
          }
        }
      }
    }
  }

  // Optionally calculate a sum-total for all servers in the current bin.
  if ($aggregate) {

    // Some variables don't logically aggregate.
    $no_aggregate = array(
      'pid',
      'time',
      'version',
      'pointer_size',
      'accepting_conns',
      'listen_disabled_num',
    );
    foreach ($stats as $bin => $servers) {
      if (is_array($servers)) {
        foreach ($servers as $server) {
          if (is_array($server)) {
            foreach ($server as $key => $value) {
              if (!in_array($key, $no_aggregate)) {
                if (isset($stats[$bin]['total'][$key])) {
                  $stats[$bin]['total'][$key] += $value;
                }
                else {
                  $stats[$bin]['total'][$key] = $value;
                }
              }
            }
          }
        }
      }
    }
  }
  return $stats;
}