Exemplo n.º 1
0
 $time = 0;
 # Requesting stats for each server
 foreach ($_ini->cluster($cluster) as $server) {
     # Start query time calculation
     $time = microtime(true);
     # Asking server for stats
     $actual[$server['hostname'] . ':' . $server['port']] = Library_Command_Factory::instance('stats_api')->stats($server['hostname'], $server['port']);
     # Calculating query time length
     $actual[$server['hostname'] . ':' . $server['port']]['query_time'] = max((microtime(true) - $time) * 1000, 1);
 }
 # Analysing stats
 foreach ($_ini->cluster($cluster) as $server) {
     # Making an alias
     $server = $server['hostname'] . ':' . $server['port'];
     # Diff between old and new dump
     $stats[$server] = Library_Analysis::diff($previous[$server], $actual[$server]);
 }
 # Making stats for each server
 foreach ($stats as $server => $array) {
     # Analysing request
     if (isset($stats[$server]['uptime']) && $stats[$server]['uptime'] > 0) {
         # Computing stats
         $stats[$server] = Library_Analysis::stats($stats[$server]);
         # Because we make a diff on every key, we must reasign some values
         $stats[$server]['bytes_percent'] = sprintf('%.1f', $actual[$server]['bytes'] / $actual[$server]['limit_maxbytes'] * 100);
         $stats[$server]['bytes'] = $actual[$server]['bytes'];
         $stats[$server]['limit_maxbytes'] = $actual[$server]['limit_maxbytes'];
         $stats[$server]['curr_connections'] = $actual[$server]['curr_connections'];
         $stats[$server]['query_time'] = $actual[$server]['query_time'];
     }
 }