setName('huawei:pon:stats') ->setDescription('Stats de PON PORTs 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") )) ; } /** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $this->output->writeln("INICIO"); $inicio = microtime(true); $oltDeviceId = (int) $input->getOption('olt-device-id'); $oltServerId = (int) $input->getOption('olt-server-id'); $oltIp = $input->getOption('olt-ip'); $oltCommunity = $input->getOption('olt-community'); $oltSnmpLibrary = $input->getOption('olt-snmp-library'); $flag = "olt_pon_stats_d_{$oltDeviceId}_s_{$oltServerId}.lock"; $key_olt_scan = "olt_scan_pons_d_{$oltDeviceId}_s_{$oltServerId}"; /* Control de bloqueo */ if($this->lock($flag)) {return;} $SNMP = new SNMP($oltIp, $oltCommunity); $library = "use".$oltSnmpLibrary; $dataCached = $this->getData($key_olt_scan, true); if(empty($dataCached)) { $this->output->writeln("Se requiere {$key_olt_scan}."); $this->removeLock($flag); return true; } //return [PONINDEX.ONUID] => value $rxPower = $SNMP->$library()->oltPonRxOpticalPower(); //return [PONINDEX] => value $txPower = $SNMP->$library()->oltPonTxOpticalPower(); $temperature = $SNMP->$library()->oltPonOpticalTemperature(); $voltage = $SNMP->$library()->oltPonOpticalVltage(); $biasCurrent = $SNMP->$library()->oltPonOpticalCurrent(); $ponStatsCached = $sendData = array(); $subId = "d_{$oltDeviceId}_s_{$oltServerId}"; $metrics = array("txPower" => "{$subId}_pon_tx_", "temperature" => "{$subId}_pon_temperature_", "voltage" => "{$subId}_pon_voltage_", "biasCurrent" => "{$subId}_pon_biascurrent_"); foreach($dataCached as $index => $pon) { $ponPort = "{$pon['slot']}.{$pon['port']}"; $stats = array(); $stats['ponPort'] = "{$pon['slot']}/{$pon['port']}"; $stats['rxPower'] = array(); foreach($metrics as $data => $metric) { if(isset($$data[$index]) && !empty($$data[$index])) { $m = "{$metric}{$ponPort}"; $v = $$data[$index] * 0.01; $stats[$data] = $v; $sendData[$m] = "{$v}|g"; } } $ponStatsCached[$index] = $stats; } foreach($rxPower as $index => $rx) { $ponPortOnuId = explode(".",$index); if(count($ponPortOnuId) != 2) continue; $indexPon = $ponPortOnuId[0]; if(isset($dataCached[$indexPon])) { $onuId = $ponPortOnuId[1]; $slot = $dataCached[$indexPon]['slot']; $port = $dataCached[$indexPon]['port']; $ponPort = "{$slot}.{$port}"; $m = "{$subId}_pon_rx_{$ponPort}.{$onuId}"; $v = $rx * 0.01; if(isset($ponStatsCached[$indexPon]['rxPower'])) { $ponStatsCached[$indexPon]['rxPower'][$onuId] = $v; } $sendData[$m] = "{$v}|g"; } } if($ponStatsCached) { $key_pon_stats = "olt_stats_pons_d_{$oltDeviceId}_s_{$oltServerId}"; $this->setData($key_pon_stats, $ponStatsCached, true); } if($sendData) { $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($flag); $fin = microtime(true); $time = $fin - $inicio; $this->output->writeln("Tiempo: $time segundos"); } }