/**
  * 上报统计数据
  * @param string $module
  * @param string $interface
  * @param bool $success
  * @param int $code
  * @param string $msg
  * @param string $report_address
  * @return boolean
  */
 public static function report($module, $interface, $success, $code, $msg, $report_address = '')
 {
     $report_address = $report_address ? $report_address : 'udp://127.0.0.1:55656';
     if (isset(self::$timeMap[$module][$interface]) && self::$timeMap[$module][$interface] > 0) {
         $time_start = self::$timeMap[$module][$interface];
         self::$timeMap[$module][$interface] = 0;
     } else {
         if (isset(self::$timeMap['']['']) && self::$timeMap[''][''] > 0) {
             $time_start = self::$timeMap[''][''];
             self::$timeMap[''][''] = 0;
         } else {
             $time_start = microtime(true);
         }
     }
     $cost_time = microtime(true) - $time_start;
     $bin_data = StatisticProtocol::encode($module, $interface, $cost_time, $success, $code, $msg);
     return self::sendData($report_address, $bin_data);
 }
示例#2
0
 /**
  * 业务处理
  * @see Man\Core.SocketWorker::dealProcess()
  */
 public function dealProcess($recv_buffer)
 {
     // 解码
     $unpack_data = StatisticProtocol::decode($recv_buffer);
     $module = $unpack_data['module'];
     $interface = $unpack_data['interface'];
     $cost_time = $unpack_data['cost_time'];
     $success = $unpack_data['success'];
     $time = $unpack_data['time'];
     $code = $unpack_data['code'];
     $msg = str_replace("\n", "<br>", $unpack_data['msg']);
     $ip = $this->getRemoteIp();
     // 模块接口统计
     $this->collectStatistics($module, $interface, $cost_time, $success, $ip, $code, $msg);
     // 全局统计
     $this->collectStatistics('WorkerMan', 'Statistics', $cost_time, $success, $ip, $code, $msg);
     // 失败记录日志
     if (!$success) {
         $this->logBuffer .= date('Y-m-d H:i:s', $time) . "\t{$ip}\t{$module}::{$interface}\tcode:{$code}\tmsg:{$msg}\n";
         if (strlen($this->logBuffer) >= self::MAX_LOG_BUFFER_SZIE) {
             $this->writeLogToDisk();
         }
     }
 }