You are here

public function MemcacheServerStatsSubscriber::onPopulateStats in Memcache API and Integration 8.2

Populates the Memcache Server Stats

Parameters

\Drupal\memcache_admin\Event\MemcacheStatsEvent $event: The event being dispatched.

Throws

\Exception

File

memcache_admin/src/EventSubscriber/MemcacheServerStatsSubscriber.php, line 42

Class

MemcacheServerStatsSubscriber
Adds memcache server specific details to the stats array.

Namespace

Drupal\memcache_admin\EventSubscriber

Code

public function onPopulateStats(MemcacheStatsEvent $event) {
  $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]);
  $memcache_servers = [];
  foreach ($servers as $server) {

    // Memcache servers report libevent version, use that for detecting stats.
    if (isset($raw_stats[$bin][$server]['libevent'])) {
      $event
        ->updateFormattedStats('memcache', $bin, $server, new MemcacheStatsObject($raw_stats[$bin][$server]));
      $event
        ->updateServers($server);
    }
  }
  if (isset($raw_stats[$bin]['total'])) {
    $event
      ->updateTotals([
      $bin => new MemcacheStatsObject($raw_stats[$bin]['total']),
    ]);
  }
}