Ejemplo n.º 1
0
 public function __construct($config = array())
 {
     if (isset($config['cacheCluster'])) {
         $memcache = new Memcache();
         $servers = Kwf_Util_Aws_ElastiCache_CacheClusterEndpoints::getCached($config['cacheCluster']);
         foreach ($servers as $s) {
             if (version_compare(phpversion('memcache'), '2.1.0') == -1 || phpversion('memcache') == '2.2.4') {
                 // < 2.1.0
                 $memcache->addServer($s['host'], $s['port'], true, 1, 1, 1);
             } else {
                 if (version_compare(phpversion('memcache'), '3.0.0') == -1) {
                     // < 3.0.0
                     $memcache->addServer($s['host'], $s['port'], true, 1, 1, 1, true, null, 10000);
                 } else {
                     $memcache->addServer($s['host'], $s['port'], true, 1, 1, 1);
                 }
             }
         }
         $config['memcache'] = $memcache;
     }
     parent::__construct($config);
 }
Ejemplo n.º 2
0
 public function getRecordValues()
 {
     $values = array();
     $load = @file_get_contents('/proc/loadavg');
     $load = explode(' ', $load);
     $values[] = $load[0];
     if (Kwf_Cache_Simple::$memcacheHost) {
         $counter = new Kwf_Benchmark_Counter_Memcache();
         $memcache = $counter->getMemcache();
         $memcacheStats = $memcache->getStats();
         $values[] = $memcacheStats['bytes_read'];
         $values[] = $memcacheStats['bytes_written'];
         $values[] = $memcacheStats['get_hits'];
         $values[] = $memcacheStats['get_misses'];
         foreach ($this->_getFieldNames() as $field) {
             $values[] = $this->_getMemcacheValue($field);
         }
     } else {
         $values[] = 'U';
         $values[] = 'U';
         $values[] = 'U';
         $values[] = 'U';
         foreach ($this->_getFieldNames() as $field) {
             $values[] = 'U';
         }
     }
     $cnt = array('processes' => 0, 'select' => 0, 'modify' => 0, 'others' => 0, 'locked' => 0);
     if (Kwf_Registry::get('dao')) {
         $dbConfig = Kwf_Registry::get('dao')->getDbConfig();
         $dbName = $dbConfig['dbname'];
         foreach (Kwf_Registry::get('db')->query('SHOW PROCESSLIST')->fetchAll() as $row) {
             if ($row['db'] != $dbName) {
                 continue;
             }
             if ($row['Command'] == 'Sleep') {
                 continue;
             }
             $sql = strtolower(trim($row['Info']));
             if ($sql == 'show processlist') {
                 continue;
             }
             $cnt['processes']++;
             if ($row['Command'] == 'Locked') {
                 $cnt['locked']++;
             }
             if (substr($sql, 0, 6) == 'select') {
                 $cnt['select']++;
             } else {
                 if (substr($sql, 0, 6) == 'update' || substr($sql, 0, 6) == 'insert' || substr($sql, 0, 7) == 'replace' || substr($sql, 0, 6) == 'delete') {
                     $cnt['modify']++;
                 } else {
                     $cnt['others']++;
                 }
             }
         }
     }
     $values = array_merge($values, array_values($cnt));
     if (Kwf_Cache_Simple::$memcacheHost) {
         $values[] = $memcacheStats['bytes'];
         $values[] = $memcacheStats['curr_items'];
         $values[] = $memcacheStats['curr_connections'];
         $values[] = $memcacheStats['limit_maxbytes'];
     } else {
         $values[] = 'U';
         $values[] = 'U';
         $values[] = 'U';
         $values[] = 'U';
     }
     return $values;
 }