function memcache_admin_stats in Zircon Profile 8.0
Same name and namespace in other branches
- 8 modules/memcache/memcache_admin/memcache_admin.module \memcache_admin_stats()
Memcache Stats page
Return value
string
1 string reference to 'memcache_admin_stats'
- memcache_admin_menu in modules/
memcache/ memcache_admin/ memcache_admin.module - Implements hook_menu().
File
- modules/
memcache/ memcache_admin/ memcache_admin.module, line 237
Code
function memcache_admin_stats($bin = 'default') {
$bin = memcache_admin_bin_mapping($bin);
$stats = dmemcache_stats($bin, 'default', TRUE);
$memcache_servers = variable_get('memcache_servers', array(
'127.0.0.1:11211' => 'default',
));
if (is_array($stats[$bin]) && count($stats[$bin])) {
$stats = $stats[$bin];
$mc = dmemcache_object($bin);
if ($mc instanceof Memcached) {
$version = t('Memcached v!version', array(
'!version' => phpversion('Memcached'),
));
}
elseif ($mc instanceof Memcache) {
$version = t('Memcache v!version', array(
'!version' => phpversion('Memcache'),
));
}
else {
$version = t('Unknown');
drupal_set_message(t('Failed to detect the memcache PECL extension.'), 'error');
}
// Building per-server stats for the current memcache bin.
$servers = array();
foreach ($memcache_servers as $server => $b) {
$b = memcache_admin_bin_mapping($b);
if ($b == $bin) {
$servers[] = $server;
if (empty($stats[$server]['uptime'])) {
drupal_set_message(t('Failed to connect to server at %server.', array(
'%server' => $server,
)), 'error');
}
$data['server_overview'][$server] = t('v!version running !uptime', array(
'!version' => check_plain($stats[$server]['version']),
'!uptime' => format_interval($stats[$server]['uptime']),
));
$data['server_pecl'][$server] = t('n/a');
$data['server_time'][$server] = format_date($stats[$server]['time']);
$data['server_connections'][$server] = _memcache_admin_stats_connections($stats[$server]);
$data['cache_sets'][$server] = _memcache_admin_stats_sets($stats[$server]);
$data['cache_gets'][$server] = _memcache_admin_stats_gets($stats[$server]);
$data['cache_counters'][$server] = _memcache_admin_stats_counters($stats[$server]);
$data['cache_transfer'][$server] = _memcache_admin_stats_transfer($stats[$server]);
$data['cache_average'][$server] = _memcache_admin_stats_average($stats[$server]);
$data['memory_available'][$server] = _memcache_admin_stats_memory($stats[$server]);
$data['memory_evictions'][$server] = number_format($stats[$server]['evictions']);
}
}
// Building a report as a custom formatted array of arrays that gets
// properly displayed by theme_memcache_admin_stats_table.
$report = array(
'Server overview' => array(
array_merge(array(
'header' => t('Uptime'),
), array(
'total' => t('n/a'),
), $data['server_overview']),
array_merge(array(
'header' => t('PECL extension'),
), array(
'total' => $version,
), $data['server_pecl']),
array_merge(array(
'header' => t('Server time'),
), array(
'total' => t('n/a'),
), $data['server_time']),
array_merge(array(
'header' => t('Connections'),
), array(
'total' => _memcache_admin_stats_connections($stats['total']),
), $data['server_connections']),
),
'Cache statistics' => array(
array_merge(array(
'header' => t('Sets'),
), array(
'total' => _memcache_admin_stats_sets($stats['total']),
), $data['cache_sets']),
array_merge(array(
'header' => t('Gets'),
), array(
'total' => _memcache_admin_stats_gets($stats['total']),
), $data['cache_gets']),
array_merge(array(
'header' => t('Counters'),
), array(
'total' => _memcache_admin_stats_counters($stats['total']),
), $data['cache_counters']),
array_merge(array(
'header' => t('Transferred'),
), array(
'total' => _memcache_admin_stats_transfer($stats['total']),
), $data['cache_transfer']),
array_merge(array(
'header' => t('Per-connection average'),
), array(
'total' => _memcache_admin_stats_average($stats['total']),
), $data['cache_average']),
),
'Memory overview' => array(
array_merge(array(
'header' => t('Available memory'),
), array(
'total' => _memcache_admin_stats_memory($stats['total']),
), $data['memory_available']),
array_merge(array(
'header' => t('Evictions'),
), array(
'total' => $stats['total']['evictions'],
), $data['memory_evictions']),
),
);
$output = theme('memcache_admin_stats_table', array(
'bin' => $bin,
'servers' => $servers,
'report' => $report,
));
}
else {
$output = '';
drupal_set_message(t('There are no statistics being reported for this bin.'), 'error');
}
return $output;
}