Clickalicious\PhpMemAdmin\App::aggregateStatistics PHP Method

aggregateStatistics() protected method

Fetch statistics for a single host or (aggregated) for a collection of hosts (cluster).
Author: Benjamin Carl ([email protected])
protected aggregateStatistics ( array $hosts = [] ) : array
$hosts array An array containing a single host or a collection of hosts to fetch statistics for.
return array The aggregated statistics
    protected function aggregateStatistics(array $hosts = array())
    {
        $result = array();
        $statistics = array();
        // Passed host(s) to this method
        foreach ($hosts as $host) {
            $currentHost = explode(':', $host);
            $client = $this->getMemcachedClient($currentHost[0], $currentHost[1], $this->getConfig()->timeout);
            $statistics[$host] = $client->stats();
        }
        // Calculate sums for cluster statistics
        foreach ($statistics as $host => $statistics) {
            foreach ($statistics as $key => $value) {
                if (isset($result[$key]) === false) {
                    $result[$key] = 0;
                }
                $value = $this->castAsPhpType($value);
                if (is_double($value) || is_int($value)) {
                    $result[$key] += $value;
                } else {
                    $result[$key] = $value;
                }
            }
        }
        return $result;
    }