/** * 取得解析后的日志数据,写入数据库。 * * @param integer $interval * @return void * @throws ZtChart_Model_Monitor_Exception */ public function extract($interval) { foreach (ZtChart_Model_Monitor_Log::getIdentifierClasses() as $identifierClass) { $logIdentifier = constant("{$identifierClass}::LOG_IDENTIFIER"); $shmIdentifier = constant("{$identifierClass}::SHM_IDENTIFIER"); $tmpfile = $this->_tmpfile($logIdentifier); if (file_put_contents($tmpfile, $this->_shmRead($shmIdentifier, true))) { $cachetime = time() - 2; // 当前服务器时间与LogServer时间可能有误差,因此设2秒冗余时间。 try { $affected = $this->_exec("LOAD DATA INFILE '{$tmpfile}' INTO TABLE {$logIdentifier} FIELDS TERMINATED BY ','"); } catch (Zend_Db_Adapter_Exception $e) { throw new ZtChart_Model_Monitor_Exception($e); } try { $assemble = new ZtChart_Model_Assemble($logIdentifier); $assemble->cacheRangeRawData($cachetime - $interval, $cachetime, Zend_Date::SECOND, 300); } catch (ZtChart_Model_Assemble_Exception $e) { $this->_logger->warn($e->getMessage()); } $this->_logger->info("{$identifierClass}: {$affected} 行数据被导入 {$logIdentifier} 表"); } @unlink($tmpfile); } }