Procházet zdrojové kódy

Updated the bandwith from OLT and ponports

Jean Sumara Leopoldo před 4 roky
rodič
revize
ab0bf9ffbd

+ 4 - 4
src/App/Service/Fiberhome/FiberhomeService.php

@@ -278,7 +278,7 @@ class FiberhomeService
                     }
                 }
 
-                $this->setOltBandwith($onu, $index, $bandwidthCached, $keyOltPonBandwith, $subId, $inOctets, $outOctets, $totalIn, $totalOut, $totalConsIn, $totalConsOut);
+                $this->setOltBandwith($onu, $index, $bandwidthCached, $subId, $inOctets, $outOctets, $totalIn, $totalOut, $totalConsIn, $totalConsOut);
             }
 
             foreach($stats as $metric => $data) {
@@ -287,6 +287,8 @@ class FiberhomeService
                 $this->redisHelper->setData($keyOnuStats, $data, true);
             }
 
+            $this->redisHelper->setData($keyOltPonBandwith, $bandwidthCached, true);
+
             $oltBandwidth = array();
             $oltBandwidth["{$subId}_inbandwidth_olt"] = "{$totalIn}|g";
             $oltBandwidth["{$subId}_outbandwidth_olt"] = "{$totalOut}|g";
@@ -323,7 +325,7 @@ class FiberhomeService
         $this->output->writeln("Tiempo: $time segundos");
     }
 
-    private function setOltBandwith($pon, $index, $bandwidthCached, $keyOltPonBandwith, $subId, $inOctets, $outOctets, &$totalIn, &$totalOut, &$totalConsIn, &$totalConsOut){
+    private function setOltBandwith($pon, $index, &$bandwidthCached, $subId, $inOctets, $outOctets, &$totalIn, &$totalOut, &$totalConsIn, &$totalConsOut){
         $t1 = time();
         $ponPort = "{$pon['slot']}.{$pon['port']}";
         $serialNumber = strtolower($pon['serialNumber']);
@@ -384,7 +386,5 @@ class FiberhomeService
         } else {
             $bandwidthCached[$index] = array('t' => $t1, 'inOct' => $in1, 'outOct' => $out1, 'inAcc' => 0, 'outAcc' => 0, 'inBand' => 0, 'outBand' => 0);
         }
-
-        $this->redisHelper->setData($keyOltPonBandwith, $bandwidthCached, true);
     }
 }

+ 50 - 0
src/App/Service/Huawei/HuaweiOltService.php

@@ -76,4 +76,54 @@ class HuaweiOltService
         }
     }
 
+    public function setConsupmitionBranwidth($inOctets, $outOctets, &$bandwidthCached, $t1, &$totalIn, &$totalOut, &$totalConsIn, &$totalConsOut, $subId){
+        (isset($inOctets[$this->huawei->getIndex()]))? $in1 = $inOctets[$this->huawei->getIndex()] : $in1 = 0;
+        (isset($outOctets[$this->huawei->getIndex()]))? $out1 = $outOctets[$this->huawei->getIndex()] : $out1 = 0;
+
+        if(isset($bandwidthCached[$this->huawei->getIndex()])) {
+            $t0 = $bandwidthCached[$this->huawei->getIndex()]['t'];
+            $in0 = $bandwidthCached[$this->huawei->getIndex()]['inOct'];
+            $out0 = $bandwidthCached[$this->huawei->getIndex()]['outOct'];
+            $inAcc = $bandwidthCached[$this->huawei->getIndex()]['inAcc'];
+            $outAcc = $bandwidthCached[$this->huawei->getIndex()]['outAcc'];
+
+            $inBandwidth = $outBandwidth = 0;
+
+            if(($in1 >= $in0) && ($t1 > $t0)) {
+                $diff = $in1 - $in0;
+                $inAcc += $diff;
+                $inBandwidth = ($diff / ($t1 - $t0)) * 8;
+            }
+
+            if(($out1 >= $out0) && ($t1 > $t0)) {
+                $diff = $out1 - $out0;
+                $outAcc += $diff;
+                $outBandwidth = ($diff / ($t1 - $t0)) * 8;
+            }
+
+            $totalIn += $inBandwidth;
+            $totalOut += $outBandwidth;
+
+            $sendData["{$subId}_inbandwidth_pon_{$this->huawei->getPonPort()}"] = "{$inBandwidth}|g";
+            $sendData["{$subId}_outbandwidth_pon_{$this->huawei->getPonPort()}"] = "{$outBandwidth}|g";
+
+            $div = 1073741824; //bytes => giga
+            $_in = number_format(($inAcc / $div),3,'.','');
+            $_out = number_format(($outAcc / $div),3,'.','');
+            $sendData["{$subId}_inconsumption_pon_{$this->huawei->getPonPort()}"] = "{$_in}|g";
+            $sendData["{$subId}_outconsumption_pon_{$this->huawei->getPonPort()}"] = "{$_out}|g";
+
+            if(date("n",$t0) != date("n",$t1)) {
+                $inAcc = $outAcc = 0;
+            }
+
+            $totalConsOut += $outAcc;
+            $totalConsIn += $inAcc;
+
+            $bandwidthCached[$this->huawei->getIndex()] = array('t' => $t1, 'inOct' => $in1, 'outOct' => $out1, 'inAcc' => $inAcc, 'outAcc' => $outAcc, 'inBand' => $inBandwidth, 'outBand' => $outBandwidth);
+        } else {
+            $bandwidthCached[$this->huawei->getIndex()] = array('t' => $t1, 'inOct' => $in1, 'outOct' => $out1, 'inAcc' => 0, 'outAcc' => 0, 'inBand' => 0, 'outBand' => 0);
+        }
+    }
+
 }

+ 1 - 4
src/App/Service/Huawei/HuaweiOnuService.php

@@ -105,7 +105,7 @@ class HuaweiOnuService
         return $this;
     }
 
-    public function setConsupmitionBranwidth($inOctets, $outOctets, $t1, &$totalIn, &$totalOut, &$totalConsIn, &$totalConsOut, $subId){
+    public function setConsupmitionBranwidth($inOctets, $outOctets, $t1, &$totalIn, &$totalOut, &$totalConsIn, &$totalConsOut){
         $inDiff = $outDiff = 0;
 
         (isset($inOctets[$this->huawei->getIndex()]))? $in1 = $inOctets[$this->huawei->getIndex()] : $in1 = 0;
@@ -135,9 +135,6 @@ class HuaweiOnuService
             $totalIn += $inBandwidth;
             $totalOut += $outBandwidth;
 
-            $this->sendData["{$subId}_inbandwidth_pon_{$this->huawei->getPonPort()}"] = "{$inBandwidth}|g";
-            $this->sendData["{$subId}_outbandwidth_pon_{$this->huawei->getPonPort()}"] = "{$outBandwidth}|g";
-
             $this->sendData["inbandwidth_onu_{$this->huawei->getSn()}"] = "{$inBandwidth}|g";
             $this->sendData["outbandwidth_onu_{$this->huawei->getSn()}"] = "{$outBandwidth}|g";
 

+ 13 - 4
src/App/Service/Huawei/HuaweiService.php

@@ -158,7 +158,7 @@ class HuaweiService
                     ->setVoltage($voltage)
                     ->setCatvRxPower($catvRxPower)
                     ->setStatus($status)
-                    ->setConsupmitionBranwidth($inOctets, $outOctets, $timeStart, $totalIn, $totalOut, $totalConsIn, $totalConsOut, $subId);
+                    ->setConsupmitionBranwidth($inOctets, $outOctets, $timeStart, $totalIn, $totalOut, $totalConsIn, $totalConsOut);
             }
 
             foreach ($stats as $metric => $data) {
@@ -280,10 +280,11 @@ class HuaweiService
         return $this;
     }
 
-    public function searchInformationsAboutOltAndSave($keyOltScanPons, $keyPonStats, $subId, $saveHistoric){
+    public function searchInformationsAboutOltAndSave($keyOltScanPons, $keyPonStats, $keyOltPonBanwidth, $subId, $saveHistoric){
         $startCmd = microtime(true);
 
         $oltScanPonsCached = $this->redisHelper->getData($keyOltScanPons, true);
+        $bandwidthCached = $this->redisHelper->getData($keyOltPonBanwidth, true);
         if(!empty($oltScanPonsCached)){
             //return [PONINDEX.ONUID] => value
             $rxPower = $this->snmpService->getSNMP($this->snmpLibrary, "oltPonRxOpticalPower","ponRxPower", $this->output);
@@ -292,11 +293,14 @@ class HuaweiService
             $temperature = $this->snmpService->getSNMP($this->snmpLibrary, "oltPonOpticalTemperature","ponTemperature", $this->output);
             $voltage = $this->snmpService->getSNMP($this->snmpLibrary, "oltPonOpticalVltage","ponVoltage", $this->output);
             $biasCurrent = $this->snmpService->getSNMP($this->snmpLibrary, "oltPonOpticalCurrent","ponBiasCurrent", $this->output);
+            $inOctets = $this->snmpService->getSNMP($this->snmpLibrary, "ifInOctets","portInOctets", $this->output);
+            $outOctets = $this->snmpService->getSNMP($this->snmpLibrary, "ifOutOctets","portOutOctets", $this->output);
 
             $ponStatsCached = [];
             $sendData = [];
-
             $huaweiOltService = new HuaweiOltService($sendData);
+            $totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
+            $timeStart = time();
 
             foreach ($oltScanPonsCached as $index => $pon){
                 $ponPort = str_replace ('/','.',$pon['ponPort']);
@@ -310,7 +314,8 @@ class HuaweiService
                     ->setVoltageOrTxPower($txPower, $subId, "txPower", "_pon_tx_")
                     ->setVoltageOrTxPower($voltage, $subId, "voltage", "_pon_voltage_")
                     ->setTemperatureOrBiasCurrent($temperature, $subId, "temperature", "_pon_temperature_")
-                    ->setTemperatureOrBiasCurrent($biasCurrent, $subId, "biasCurrent", "_pon_biascurrent_");
+                    ->setTemperatureOrBiasCurrent($biasCurrent, $subId, "biasCurrent", "_pon_biascurrent_")
+                    ->setConsupmitionBranwidth($inOctets, $outOctets, $bandwidthCached, $timeStart, $totalIn, $totalOut, $totalConsOut, $totalConsOut, $subId);
 
                 $ponStatsCached[$index] = $stats;
             }
@@ -326,6 +331,10 @@ class HuaweiService
                 $this->redisHelper->setData($keyPonStats, $ponStatsCached, true);
             }
 
+            if($bandwidthCached) {
+                $this->redisHelper->setData($keyOltPonBanwidth, $bandwidthCached, true);
+            }
+
             if($sendData && $saveHistoric) {
                 $timeStartScript = microtime(true);
                 (new StatsDService())->send($sendData);

+ 2 - 1
src/Command/Huawei/HuaweiOltScanCommand.php

@@ -43,12 +43,13 @@ class HuaweiOltScanCommand extends BaseCommand
         $keyOltScanPons = "olt_scan_pons_{$this->d_s}";
         $keyPonStats = "olt_stats_pons_{$this->d_s}";
         $keyOltScan = "olt_scan_{$this->d_s}";
+        $keyOltPonBanwidth = "olt_bandwidth_pons_{$this->d_s}";
         $huaweiService = new HuaweiService($SNMP->$library(), $output, $this->flag);
 
         $huaweiService
             ->searchOltMemoryAndCpu($keyOltScanCard)
             ->searchPonAndSaveCache($keyOltScanPons)
-            ->searchInformationsAboutOltAndSave($keyOltScanPons, $keyPonStats, $this->d_s, $saveHistoric)
+            ->searchInformationsAboutOltAndSave($keyOltScanPons, $keyPonStats, $keyOltPonBanwidth, $this->d_s, $saveHistoric)
             ->searchNumberSerialAndSaveCache($keyOltScan, $keyOltScanPons)
             ->searchOnuStatusAndSave($keyOltScan, $this->d_s);