Преглед изворни кода

Merge branch 'master' of https://bitbucket.org/ikflowdat/huaweibundle

root пре 6 година
родитељ
комит
45840d567d
2 измењених фајлова са 42 додато и 11 уклоњено
  1. 33 8
      Command/HuaweiOnuOctetsCommand.php
  2. 9 3
      Command/HuaweiPonOctetsCommand.php

+ 33 - 8
Command/HuaweiOnuOctetsCommand.php

@@ -60,14 +60,14 @@ class HuaweiOnuOctetsCommand extends BaseCommand
         $inOctets = $this->getSNMP("onuInOctets","onuInOctets");
         $outOctets = $this->getSNMP("onuOutOctets","onuOutOctets");
 
-        $sendData = array();
+        $consumptionData = $sendData = array();
 
         $subId = $this->d_s;
         
         $t1 = time();
         $totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
         foreach($dataCached as $index => $onu) {
-            
+            $inDiff = $outDiff = 0;
             $sn = $onu["serialNumber"];
             
             (isset($inOctets[$index]))? $in1 = $inOctets[$index] : $in1 = 0;
@@ -83,13 +83,13 @@ class HuaweiOnuOctetsCommand extends BaseCommand
                 $inBandwidth = $outBandwidth = 0; 
                  
                 if(($in1 >= $in0) && ($t1 > $t0)) {
-                    $diff = $in1 - $in0;
+                    $inDiff = $diff = $in1 - $in0;
                     $inAcc += $diff;
                     $inBandwidth = ($diff / ($t1 - $t0)) * 8;
                 }
-
+                
                 if(($out1 >= $out0) && ($t1 > $t0)) {
-                    $diff = $out1 - $out0;
+                    $outDiff = $diff = $out1 - $out0;
                     $outAcc += $diff;
                     $outBandwidth = ($diff / ($t1 - $t0)) * 8;
                 }
@@ -101,13 +101,23 @@ class HuaweiOnuOctetsCommand extends BaseCommand
                 $sendData["outbandwidth_onu_{$sn}"] = "{$outBandwidth}|g";
 
                 $div = 1073741824; //bytes => giga
-                $consIn = number_format(($inAcc / $div),3);
-                $consOut = number_format(($outAcc / $div),3);
+                $consIn = number_format(($inAcc / $div),3,'.','');
+                $consOut = number_format(($outAcc / $div),3,'.','');
                 
                 $sendData["inconsumption_onu_{$sn}"] = "{$consIn}|g";
                 $sendData["outconsumption_onu_{$sn}"] = "{$consOut}|g";
 
-                if(date("d",$t0) != date("d",$t1)) {
+                $div = 1073741824; //bytes => giga
+                $inGB =  number_format($inDiff / $div, 5,".","");
+                $outGB = number_format($outDiff / $div, 5,".","");
+                $server = $this->oltServerId;
+                $fatherDevice = $this->oltDeviceId;
+                $fatherDeviceType = 2;
+                $device = $sn;
+                $date = date("Y-m-d");
+                $consumptionData[] = "({$server},{$fatherDevice}, {$fatherDeviceType},'{$device}','{$date}',{$inGB},{$outGB})";
+
+                if(date("n",$t0) != date("n",$t1)) {
                     $inAcc = $outAcc = 0;
                 }
 
@@ -120,7 +130,10 @@ class HuaweiOnuOctetsCommand extends BaseCommand
             }
         }
 
+        
         $this->setData($key_olt_onu_bandwidth, $bandwidthCached, true);
+
+        $this->saveConsumption($consumptionData);
         
         if($sendData && $saveHistoric) {
             $t_start_script = microtime(true); 
@@ -140,4 +153,16 @@ class HuaweiOnuOctetsCommand extends BaseCommand
         
     }
 
+    /**
+     * @param array $data
+     */
+    function saveConsumption($data)
+    {
+        if ($data) {
+            $query = "INSERT LOW_PRIORITY INTO `device_consumption` (`server_id`, `father_device_id`, `father_device_type`, `device`, `date`,`cons_in`,`cons_out`) VALUES " . implode(",", $data) . " ON DUPLICATE KEY UPDATE cons_out = cons_out + VALUES(cons_out), cons_in = cons_in + VALUES(cons_in);";
+            $this->executeQueries(array($query));
+            
+        }
+    }
+
 }

+ 9 - 3
Command/HuaweiPonOctetsCommand.php

@@ -102,7 +102,13 @@ class HuaweiPonOctetsCommand extends BaseCommand
                 $sendData["{$subId}_inbandwidth_pon_{$ponPort}"] = "{$inBandwidth}|g";
                 $sendData["{$subId}_outbandwidth_pon_{$ponPort}"] = "{$outBandwidth}|g";
 
-                if(date("d",$t0) != date("d",$t1)) {
+                $div = 1073741824; //bytes => giga
+                $_in = number_format(($inAcc / $div),3,'.','');
+                $_out = number_format(($outAcc / $div),3,'.','');
+                $sendData["{$subId}_inconsumption_pon_{$ponPort}"] = "{$_in}|g";
+                $sendData["{$subId}_outconsumption_pon_{$ponPort}"] = "{$_out}|g";
+
+                if(date("n",$t0) != date("n",$t1)) {
                     $inAcc = $outAcc = 0;
                 }
 
@@ -122,8 +128,8 @@ class HuaweiPonOctetsCommand extends BaseCommand
         $oltBandwidth["{$subId}_outbandwidth_olt"] = "{$totalOut}|g";
 
         $div = 1073741824; //bytes => giga
-        $consIn = number_format(($totalConsIn / $div),3);
-        $consOut = number_format(($totalConsOut / $div),3);
+        $consIn = number_format(($totalConsIn / $div),3,'.','');
+        $consOut = number_format(($totalConsOut / $div),3,'.','');
         $oltConsumption = array();
         $oltConsumption["{$subId}_inconsumption_olt"] = "{$consIn}|g";
         $oltConsumption["{$subId}_outconsumption_olt"] = "{$consOut}|g";