|
@@ -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");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|