public function McrouterStatsSubscriber::onPopulateStats in Memcache API and Integration 8.2
Adds stats to the memcache event.
Parameters
\Drupal\memcache_admin\Event\MemcacheStatsEvent $event: The event being dispatched.
Throws
\Exception
File
- memcache_admin/
src/ EventSubscriber/ McrouterStatsSubscriber.php, line 39
Class
- McrouterStatsSubscriber
- Adds memcache server specific details to the stats array.
Namespace
Drupal\memcache_admin\EventSubscriberCode
public function onPopulateStats(MemcacheStatsEvent $event) {
$memcache = $event
->getMemcache();
if (!$memcache
->getMemcache()
->get('__mcrouter__.version')) {
return;
}
$raw_stats = $event
->getRawStats();
$bin = $event
->getCacheBin();
// No cache bin data, return.
if (!isset($raw_stats[$bin])) {
return;
}
// No servers found, return.
if (!is_array($raw_stats[$bin])) {
return;
}
$servers = array_keys($raw_stats[$bin]);
foreach ($servers as $server) {
if ($server == 'total') {
continue;
}
// McRouter reports num_servers use that for detecting stats.
if (isset($raw_stats[$bin][$server]['num_servers'])) {
$event
->updateFormattedStats('memcache', $bin, $server, new McrouterStatsObject($raw_stats[$bin][$server]));
$event
->updateServers($server);
}
}
}