Commit 63bc6f2f authored by Jeremy's avatar Jeremy

Issue #293902 by Jeremy: Improved admin statistics.

parent 687433da
......@@ -204,30 +204,62 @@ function dmemcache_flush($bin = 'cache', $mc = NULL) {
}
}
function dmemcache_stats($bin = 'cache', $type = '') {
// resolve requests for 'default' type to ''
if ($type == 'default') {
$type = '';
}
// resolve requests for 'default' bin to 'cache'.
if ($bin == 'default') {
$bin = 'cache';
}
if ($mc = dmemcache_object($bin)) {
if ($mc instanceof Memcached) {
return $mc->getStats();
}
// The PHP Memcache extension 3.x version throws an error if the stats
// type is NULL or not in {reset, malloc, slabs, cachedump, items, sizes}.
// If $type is 'default', then no parameter should be passed to the
// Memcache memcache_get_extended_stats() function.
if ($type == 'default' || $type == '') {
return $mc->getExtendedStats();
function dmemcache_stats($stats_bin = 'cache', $stats_type = 'default', $aggregate = FALSE) {
$memcache_bins = variable_get('memcache_bins', array('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;
foreach ($memcache_bins as $bin => $target) {
if ($stats_bin == $bin) {
if ($mc = dmemcache_object($bin)) {
if ($mc instanceof Memcached) {
$stats[$bin] = $mc->getStats();
}
// The PHP Memcache extension 3.x version throws an error if the stats
// type is NULL or not in {reset, malloc, slabs, cachedump, items,
// sizes}. If $stats_type is 'default', then no parameter should be
// passed to the Memcache memcache_get_extended_stats() function.
else if ($mc instanceof Memcache) {
if ($stats_type == 'default' || $stats_type == '') {
$stats[$bin] = $mc->getExtendedStats();
}
// If $slab isn't zero, then we are dumping the contents of a
// specific cache slab.
else if (!empty($slab)) {
$stats[$bin] = $mc->getStats('cachedump', $slab);
}
else {
$stats[$bin] = $mc->getExtendedStats($stats_type);
}
}
}
}
else {
return $mc->getExtendedStats($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;
}
/**
......@@ -310,6 +342,8 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
foreach ($default_opts as $key => $value) {
$memcache->setOption($key, $value);
}
// See README.txt for setting custom Memcache options when using the
// memcached PECL extension.
$memconf = variable_get('memcache_options', array());
foreach ($memconf as $key => $value) {
$memcache->setOption($key, $value);
......@@ -355,10 +389,8 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
$memcache->addServer($host, $port, $memcache_persistent);
}
}
else {
if ($memcache->addServer($host, $port) && !$init) {
$init = TRUE;
}
else if ($memcache->addServer($host, $port) && !$init) {
$init = TRUE;
}
}
}
......
......@@ -43,3 +43,8 @@ function memcache_requirements($phase) {
}
return $requirements;
}
function memcache_admin_update_7001() {
drupal_flush_all_caches();
menu_rebuild();
}
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment