You are here

public function MemcacheStatsObject::getConnectionAvg in Memcache API and Integration 8.2

@inheritDoc

Overrides MemcacheStatsInterface::getConnectionAvg

1 method overrides MemcacheStatsObject::getConnectionAvg()
McrouterStatsObject::getConnectionAvg in memcache_admin/src/Stats/McrouterStatsObject.php
@inheritDoc

File

memcache_admin/src/Stats/MemcacheStatsObject.php, line 199

Class

MemcacheStatsObject
Class MemcacheStats.

Namespace

Drupal\memcache_admin\Stats

Code

public function getConnectionAvg() : string {
  if (!isset($this->stats['total_connections']) || !isset($this->stats['cmd_get']) || !isset($this->stats['cmd_set']) || !isset($this->stats['bytes_written']) || !isset($this->stats['bytes_read'])) {
    return self::NA;
  }
  if ($this->stats['total_connections'] == 0) {
    $get = 0;
    $set = 0;
    $read = 0;
    $write = 0;
  }
  else {
    $get = $this->stats['cmd_get'] / $this->stats['total_connections'];
    $set = $this->stats['cmd_set'] / $this->stats['total_connections'];
    $read = $this->stats['bytes_written'] / $this->stats['total_connections'];
    $write = $this->stats['bytes_read'] / $this->stats['total_connections'];
  }
  return $this
    ->t('@read in @get gets; @write in @set sets', [
    '@get' => number_format($get, 2),
    '@set' => number_format($set, 2),
    '@read' => format_size((int) number_format($read, 2)),
    '@write' => format_size((int) number_format($write, 2)),
  ]);
}