Bladeren bron

FD3-359 se agrega comando para leer y guardar octetos y acumulados de las ONUs.

Maxi Schvindt 7 jaren geleden
bovenliggende
commit
11da7e9f75
2 gewijzigde bestanden met toevoegingen van 157 en 2 verwijderingen
  1. 144 0
      Command/HuaweiOnuOctetsCommand.php
  2. 13 2
      SNMP/MIBS/OIDSHuaweiV1.php

+ 144 - 0
Command/HuaweiOnuOctetsCommand.php

@@ -0,0 +1,144 @@
+<?php
+
+namespace HuaweiBundle\Command;
+
+use BaseStatsBundle\Command\BaseCommand;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use HuaweiBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class HuaweiOnuOctetsCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('huawei:onu:octets')
+            ->setDescription('Bandwidth ONTs de OLT')
+            ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
+            ->setDefinition(array(
+                new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1),
+                new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1),
+                new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"),
+                new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"),
+                new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP"),
+                new InputOption('save-historic', null, InputOption::VALUE_OPTIONAL, "Send data to StatsD",1)
+            ))
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        parent::execute($input, $output);
+        
+        $key_olt_scan = "olt_scan_{$this->d_s}";
+        $key_olt_onu_bandwidth = "olt_bandwidth_onu_{$this->d_s}";
+        $saveHistoric = (int) $input->getOption('save-historic');
+        $inicio = microtime(true);
+
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
+        
+        $dataCached = $this->getData($key_olt_scan, true);
+        $bandwidthCached = $this->getData($key_olt_onu_bandwidth, true);
+
+        if(empty($dataCached)) {
+            $this->output->writeln("Se requiere {$key_olt_scan}.");
+            $this->removeLock($this->flag);
+            return true;
+        }
+
+        //counter64
+        $inOctets = $this->getSNMP("onuInOctets","onuInOctets");
+        $outOctets = $this->getSNMP("onuOutOctets","onuOutOctets");
+
+        //print_r($dataCached);
+        //print_r($inOctets);
+        //print_r($outOctets);
+        //$key_olt_pon_bandwidth = "olt_bandwidth_pons_{$this->d_s}";
+        //$aux = $this->getData($key_olt_pon_bandwidth, true);
+        //print_r($aux[4194312192]);
+        //die;
+
+        $sendData = array();
+
+        $subId = $this->d_s;
+        
+        $t1 = time();
+        $totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
+        foreach($dataCached as $index => $onu) {
+            
+            $sn = $onu["serialNumber"];
+            
+            (isset($inOctets[$index]))? $in1 = $inOctets[$index] : $in1 = 0;
+            (isset($outOctets[$index]))? $out1 = $outOctets[$index] : $out1 = 0;
+
+            if(isset($bandwidthCached[$index])) {
+                $t0 = $bandwidthCached[$index]['t'];
+                $in0 = $bandwidthCached[$index]['inOct'];
+                $out0 = $bandwidthCached[$index]['outOct'];
+                $inAcc = $bandwidthCached[$index]['inAcc'];
+                $outAcc = $bandwidthCached[$index]['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["inbandwidth_onu_{$sn}"] = "{$inBandwidth}|g";
+                $sendData["outbandwidth_onu_{$sn}"] = "{$outBandwidth}|g";
+
+                if(date("d",$t0) != date("d",$t1)) {
+                    $inAcc = $outAcc = 0;
+                }
+
+                $totalConsOut += $outAcc;
+                $totalConsIn += $inAcc;
+                
+                $bandwidthCached[$index] = array('t' => $t1, 'inOct' => $in1, 'outOct' => $out1, 'inAcc' => $inAcc, 'outAcc' => $outAcc, 'inBand' => $inBandwidth, 'outBand' => $outBandwidth);
+            } else {
+                $bandwidthCached[$index] = array('t' => $t1, 'inOct' => $in1, 'outOct' => $out1, 'inAcc' => 0, 'outAcc' => 0, 'inBand' => 0, 'outBand' => 0);
+            }
+        }
+
+        $this->setData($key_olt_onu_bandwidth, $bandwidthCached, true);
+        
+        if($sendData && $saveHistoric) {
+            $t_start_script = microtime(true); 
+            $statsdService = $this->getContainer()->get('statsd');
+            $statsdService->send($sendData);
+            $t_end_script = microtime(true); 
+            $time = $t_end_script - $t_start_script;
+            print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: ".count($sendData).PHP_EOL);
+        }
+
+        /* Fin de bloqueo */
+        $this->removeLock($this->flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos");
+        
+    }
+
+}

+ 13 - 2
SNMP/MIBS/OIDSHuaweiV1.php

@@ -12,7 +12,7 @@ class OIDSHuaweiV1 extends \HuaweiBundle\SNMP\MIB {
     const OID_authOnuListSlot               = "1.3.6.1.4.1.5875.800.3.10.1.1.2";
     const OID_authOnuListPon                = "1.3.6.1.4.1.5875.800.3.10.1.1.3";
     const OID_authOnuListOnuid              = "1.3.6.1.4.1.5875.800.3.10.1.1.4";
-    
+                                            // 1.3.6.1.4.1.2011.6.128.1.1.4.42.1.3
     const OID_authOnuListMac                = "1.3.6.1.4.1.2011.6.128.1.1.2.43.1.3";
     const OID_onuPonRxOpticalPower          = "1.3.6.1.4.1.2011.6.128.1.1.2.51.1.4";
     const OID_onuPonTxOpticalPower          = "1.3.6.1.4.1.2011.6.128.1.1.2.51.1.3";
@@ -30,7 +30,7 @@ class OIDSHuaweiV1 extends \HuaweiBundle\SNMP\MIB {
     const OID_oltPonOpticalVltage                 = "1.3.6.1.4.1.2011.6.128.1.1.2.23.1.2";
     const OID_oltPonOpticalCurrent                = "1.3.6.1.4.1.2011.6.128.1.1.2.23.1.3";
     const OID_oltPonOpticalTemperature            = "1.3.6.1.4.1.2011.6.128.1.1.2.23.1.1";
-    
+                                                    //1.3.6.1.4.1.2011.6.128.1.1.4.42.1.3
     
     //Genericos
     const OID_ifHCInOctets                        = "1.3.6.1.2.1.31.1.1.1.6";
@@ -42,6 +42,9 @@ class OIDSHuaweiV1 extends \HuaweiBundle\SNMP\MIB {
     const OID_cardCpu                   = "1.3.6.1.4.1.2011.2.6.7.1.1.2.1.5";
     const OID_cardMemory                = "1.3.6.1.4.1.2011.2.6.7.1.1.2.1.6";
 
+    const OID_hwGponOntStatisticUpBytes = "1.3.6.1.4.1.2011.6.128.1.1.4.23.1.3"; //Counter64
+    const OID_hwGponOntStatisticDownBytes = "1.3.6.1.4.1.2011.6.128.1.1.4.23.1.4"; //Counter64
+
     function convertIndex($index, $values) {
         $data = array();
         foreach($values as $i => $v) {
@@ -181,4 +184,12 @@ class OIDSHuaweiV1 extends \HuaweiBundle\SNMP\MIB {
     public function oltCardMemory($index = null) {
         return $this->getSNMP()->lastOidWalk(self::OID_cardMemory,16);
     }
+    
+    public function onuInOctets($index = null) {
+        return $this->getSNMP()->lastOidWalk(self::OID_hwGponOntStatisticUpBytes,16);
+    }
+    
+    public function onuOutOctets($index = null) {
+        return $this->getSNMP()->lastOidWalk(self::OID_hwGponOntStatisticDownBytes,16);
+    }
 }