class McrouterStatsSubscriber in Memcache API and Integration 8.2
Adds memcache server specific details to the stats array.
Hierarchy
- class \Drupal\memcache_admin\EventSubscriber\McrouterStatsSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses MessengerTrait, StringTranslationTrait
Expanded class hierarchy of McrouterStatsSubscriber
1 string reference to 'McrouterStatsSubscriber'
- memcache_admin.services.yml in memcache_admin/
memcache_admin.services.yml - memcache_admin/memcache_admin.services.yml
1 service uses McrouterStatsSubscriber
File
- memcache_admin/
src/ EventSubscriber/ McrouterStatsSubscriber.php, line 15
Namespace
Drupal\memcache_admin\EventSubscriberView source
class McrouterStatsSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
use MessengerTrait;
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[MemcacheStatsEvent::BUILD_MEMCACHE_STATS][] = [
'onPopulateStats',
100,
];
return $events;
}
/**
* Adds stats to the memcache event.
*
* @param \Drupal\memcache_admin\Event\MemcacheStatsEvent $event
* The event being dispatched.
*
* @throws \Exception
*/
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);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
McrouterStatsSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
McrouterStatsSubscriber:: |
public | function | Adds stats to the memcache event. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |