You are here

class McrouterStatsSubscriber in Memcache API and Integration 8.2

Adds memcache server specific details to the stats array.

Hierarchy

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
memcache_stats.mcrouter in memcache_admin/memcache_admin.services.yml
Drupal\memcache_admin\EventSubscriber\McrouterStatsSubscriber

File

memcache_admin/src/EventSubscriber/McrouterStatsSubscriber.php, line 15

Namespace

Drupal\memcache_admin\EventSubscriber
View 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

Namesort descending Modifiers Type Description Overrides
McrouterStatsSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
McrouterStatsSubscriber::onPopulateStats public function Adds stats to the memcache event.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.