瀏覽代碼

统计相关

walkor 11 年之前
父節點
當前提交
81056a554f

+ 11 - 1
applications/Statistics/Clients/StatisticClient.php

@@ -1,5 +1,5 @@
 <?php
-require_once WORKERMAN_ROOT_DIR . 'applications/Statistics/Lib/StatisticProtocol.php'; 
+require_once  __DIR__ . '/../Lib/StatisticProtocol.php'; 
 /**
  * 统计客户端
  * @author workerman.net
@@ -74,4 +74,14 @@ class StatisticClient
         return stream_socket_sendto($socket, $buffer) == strlen($buffer);
     }
     
+}
+
+if(PHP_SAPI == 'cli' && isset($argv[0]) && $argv[0] == basename(__FILE__))
+{
+    StatisticClient::tick("TestModule", 'TestInterface');
+    usleep(rand(10000, 600000));
+    $success = rand(0,1);
+    $code = rand(300, 400);
+    $msg = '这个是测试消息';
+    var_export(StatisticClient::report('TestModule', 'TestInterface', $success, $code, $msg));;
 }

+ 1 - 1
applications/Statistics/Lib/StatisticProtocol.php

@@ -88,7 +88,7 @@ class StatisticProtocol
     public static function decode($bin_data)
     {
         // 解包
-        $data = unpack("Cmodule_name_len/Cinterface_name_len/fcost_time/Csuccess/Ncode/nmsg_len/Ntime", $data);
+        $data = unpack("Cmodule_name_len/Cinterface_name_len/fcost_time/Csuccess/Ncode/nmsg_len/Ntime", $bin_data);
         $module = substr($bin_data, self::PACKEGE_FIXED_LENGTH, $data['module_name_len']);
         $interface = substr($bin_data, self::PACKEGE_FIXED_LENGTH + $data['module_name_len'], $data['interface_name_len']);
         $msg = substr($bin_data, self::PACKEGE_FIXED_LENGTH + $data['module_name_len'] + $data['interface_name_len']);

+ 2 - 2
workers/StatisticWorker.php

@@ -33,7 +33,7 @@ class StatisticWorker extends Man\Core\SocketWorker
     
     /**
      * 统计数据 
-     * ip=>modid=>interface=>['code'=>[xx=>count,xx=>count],'suc_cost_time'=>xx,'fail_cost_time'=>xx, 'suc_count'=>xx, 'fail_count'=>xx, 'time'=>xxx]
+     * ip=>modid=>interface=>['code'=>[xx=>count,xx=>count],'suc_cost_time'=>xx,'fail_cost_time'=>xx, 'suc_count'=>xx, 'fail_count'=>xx]
      * @var array
      */
     protected $statisticData = array();
@@ -118,7 +118,7 @@ class StatisticWorker extends Man\Core\SocketWorker
        }
        if(!isset($this->statisticData[$ip][$module][$interface]))
        {
-           $this->statisticData[$ip][$module][$interface] = array('code'=>array(), 'suc_cost_time'=>0, 'fail_cost_time'=>0, 'suc_count'=>0, 'fail_count'=>0, 'time'=>$this->stLastWriteTime);
+           $this->statisticData[$ip][$module][$interface] = array('code'=>array(), 'suc_cost_time'=>0, 'fail_cost_time'=>0, 'suc_count'=>0, 'fail_count'=>0);
        }
        if(!isset($this->statisticData[$ip][$module][$interface]['code'][$code]))
        {