Pārlūkot izejas kodu

Update stats command to get informations about OLT on Huawei

Jean Sumara Leopoldo 5 gadi atpakaļ
vecāks
revīzija
97203652ca

+ 0 - 3
bin/console

@@ -2,7 +2,6 @@
 <?php
 require __DIR__ . '/../vendor/autoload.php';
 
-use Dotenv\Dotenv;
 use Flowdat\Stats\Command\Fiberhome\FiberhomeOltScanCommand;
 use Flowdat\Stats\Command\Fiberhome\FiberhomeOnuScanCommand;
 use Flowdat\Stats\Command\Huawei\HuaweiOltScanCommand;
@@ -13,8 +12,6 @@ use Flowdat\Stats\Command\Zte\ZteOnuScanCommand;
 use Symfony\Component\Console\Application;
 
 require __DIR__.'/../vendor/autoload.php';
-$dotEnv = Dotenv::createImmutable(__DIR__.'/../');
-$dotEnv->load();
 
 $application = new Application();
 $application->add(new HuaweiOltScanCommand());

+ 4 - 4
src/App/Helper/RedisHelper.php

@@ -62,8 +62,8 @@ class RedisHelper
 
     public static function lock($flag)
     {
-        $modeConnect = $_ENV['DEV_MODE'] ? array("tcp://172.16.0.7:6379") : array("tcp://redis:6379");
-        $redis = new Redis(array($modeConnect));
+        $redisConnection = "tcp://redis:6379";
+        $redis = new Redis(array($redisConnection));
         $redis->connect();
 
         $store = new RedisStore($redis);
@@ -89,8 +89,8 @@ class RedisHelper
 
     public static function removeLock($flag)
     {
-        $modeConnect = $_ENV['DEV_MODE'] ? array("tcp://172.16.0.7:6379") : array("tcp://redis:6379");
-        $redis = new Redis(array($modeConnect));
+        $redisConnection = "tcp://redis:6379";
+        $redis = new Redis(array($redisConnection));
         $redis->connect();
 
         $store = new RedisStore($redis);

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

@@ -105,7 +105,7 @@ class HuaweiOnuService
         return $this;
     }
 
-    public function setConsupmitionBranwidth($inOctets, $outOctets, $t1){
+    public function setConsupmitionBranwidth($inOctets, $outOctets, $t1, &$totalIn, &$totalOut, &$totalConsIn, &$totalConsOut, $subId){
         $inDiff = $outDiff = 0;
 
         (isset($inOctets[$this->huawei->getIndex()]))? $in1 = $inOctets[$this->huawei->getIndex()] : $in1 = 0;
@@ -132,6 +132,12 @@ class HuaweiOnuService
                 $outBandwidth = ($diff / ($t1 - $t0)) * 8;
             }
 
+            $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";
 
@@ -156,6 +162,9 @@ class HuaweiOnuService
                 $inAcc = $outAcc = 0;
             }
 
+            $totalConsOut += $outAcc;
+            $totalConsIn += $inAcc;
+
             $this->bandwidthCached[$this->huawei->getIndex()] = array('sn' => $this->huawei->getSn(), 't' => $t1, 'inOct' => $in1, 'outOct' => $out1, 'inAcc' => $inAcc, 'outAcc' => $outAcc, 'inBand' => $inBandwidth, 'outBand' => $outBandwidth);
         } else {
             $this->bandwidthCached[$this->huawei->getIndex()] = array('sn' => $this->huawei->getSn(), 't' => $t1, 'inOct' => $in1, 'outOct' => $out1, 'inAcc' => 0, 'outAcc' => 0, 'inBand' => 0, 'outBand' => 0);

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

@@ -122,7 +122,7 @@ class HuaweiService
         return $this;
     }
 
-    public function searchInformationsAboutOnuAndSave($keyOltScan, $keyOltBandwidthOnu, $oltServerId, $oltDeviceId, $saveHistoric){
+    public function searchInformationsAboutOnuAndSave($keyOltScan, $keyOltBandwidthOnu, $oltServerId, $oltDeviceId, $subId, $saveHistoric){
         $startCmd = microtime(true);
         $serialNumberCache = $this->redisHelper->getData($keyOltScan, true);
 
@@ -141,31 +141,53 @@ class HuaweiService
             $stats = [];
             $sendData = [];
             $consumptionData = [];
+            $totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
 
             $huaweiOnuService = new HuaweiOnuService($sendData, $stats, $consumptionData, $onuBandwithCache, $oltServerId, $oltDeviceId);
 
             $timeStart = time();
             foreach($serialNumberCache as $index => $onu){
                 $sn = strtolower($onu['serialNumber']);
+                $ponPort = str_replace("/", ".", $onu['ponPort']);
 
                 $huaweiOnuService
-                    ->configure(new Huawei($index, $sn))
+                    ->configure(new Huawei($index, $sn, $ponPort))
                     ->setPowerOnu($txPower, "onu_tx_")
                     ->setPowerOnu($rxPower, "onu_rx_")
                     ->setTemperatureOnu($temperature)
                     ->setVoltage($voltage)
                     ->setCatvRxPower($catvRxPower)
                     ->setStatus($status)
-                    ->setConsupmitionBranwidth($inOctets, $outOctets, $timeStart);
+                    ->setConsupmitionBranwidth($inOctets, $outOctets, $timeStart, $totalIn, $totalOut, $totalConsIn, $totalConsOut, $subId);
             }
 
             foreach ($stats as $metric => $data) {
-                $key_onu_stats = "{$metric}{$this->flagCmd}";
+                $key_onu_stats = "{$metric}{$subId}";
 
                 $this->redisHelper->setData($key_onu_stats, $data, true);
             }
 
             $this->redisHelper->setData($keyOltBandwidthOnu, $onuBandwithCache, true);
+
+            $oltBandwidth = array();
+            $oltBandwidth["{$subId}_inbandwidth_olt"] = "{$totalIn}|g";
+            $oltBandwidth["{$subId}_outbandwidth_olt"] = "{$totalOut}|g";
+
+            $div = 1073741824; //bytes => giga
+            $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";
+
+            $statsdService = new StatsDService();
+            $statsdService->send($oltBandwidth);
+            $statsdService->send($oltConsumption);
+
+            $endCmd = microtime(true);
+            $time = $endCmd - $startCmd;
+            $this->output->writeln("Tiempo: $time segundos");
+
             $this->saveConsumption($consumptionData);
 
             if ($sendData && $saveHistoric) {

+ 1 - 2
src/App/Service/Redis/RedisService.php

@@ -19,8 +19,7 @@ class RedisService implements CollectorInterface
      */
     public function __construct()
     {
-        $modeConnect = $_ENV['DEV_MODE'] ? array("tcp://172.16.0.7:6379") : array("tcp://redis:6379");
-        $this->redis = new Redis($modeConnect);
+        $this->redis = new Redis(array("tcp://redis:6379"));
     }
 
     /**

+ 1 - 2
src/App/Service/StatsD/StatsDService.php

@@ -9,10 +9,9 @@ use Exception;
 class StatsDService
 {
     public function __construct(){
-        $hostConnection = $_ENV['DEV_MODE'] ? '172.16.0.25' : 'statsd';
         $this->config = array();
         $this->config["enabled"] = true;
-        $this->config["host"] = $hostConnection;
+        $this->config["host"] = 'statsd';
         $this->config["port"] = 8125;
     }
 

+ 1 - 1
src/Command/Huawei/HuaweiOnuScanCommand.php

@@ -52,7 +52,7 @@ class HuaweiOnuScanCommand extends BaseCommand
         $huaweiService
             ->searchPonAndSaveCache($keyOltScanPon)
             ->searchNumberSerialAndSaveCache($keyOltScan, $keyOltScanPon)
-            ->searchInformationsAboutOnuAndSave($keyOltScan, $keyOltBandwidthOnu, $this->oltServerId, $this->oltDeviceId, $saveHistoric);
+            ->searchInformationsAboutOnuAndSave($keyOltScan, $keyOltBandwidthOnu, $this->oltServerId, $this->oltDeviceId, $this->d_s, $saveHistoric);
 
         $statsService = new StatsService();
         $statsService->updateStatsOnu($this->oltDeviceId, $this->oltServerId);

+ 3 - 4
src/Domain/Doctrine.php

@@ -19,13 +19,12 @@ class Doctrine
     {
         $config = Setup::createAnnotationMetadataConfiguration([__DIR__."/src"], getenv('DEV_MODE'));
 
-        $hostConnect = $_ENV['DEV_MODE'] ? '172.16.0.4' : 'mysql';
         $connectionOptions = array(
             'driver'   => 'pdo_mysql',
-            'host'     => $hostConnect,
+            'host'     => 'mysql',
             'dbname'   => 'fd3_stats',
-            'user'     => $_ENV['DEV_MODE'] ? $_ENV['USER_MYSQL'] : getenv('MYSQL_USER'),
-            'password' => $_ENV['DEV_MODE'] ? $_ENV['PASSWORD_MYSQL'] : getenv('MYSQL_PASSWORD')
+            'user'     => getenv('MYSQL_USER'),
+            'password' => getenv('MYSQL_PASSWORD')
         );
 
         try {