setName('fiberlink: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"), 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); $saveHistoric = (int) $input->getOption('save-historic'); $key_olt_scan = "olt_scan_pons_{$this->d_s}"; $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); if(empty($dataCached)) { $this->output->writeln("Se requiere {$key_olt_scan}."); $this->removeLock($this->flag); return true; } //return [PONINDEX] => value $rxPower = $this->getSNMP("oltPonRxOpticalPower","ponRxPower"); $txPower = $this->getSNMP("oltPonTxOpticalPower","ponTxPower"); $temperature = $this->getSNMP("oltPonOpticalTemperature","ponTemperature"); $voltage = $this->getSNMP("oltPonOpticalVltage","ponVoltage"); $biasCurrent = $this->getSNMP("oltPonOpticalCurrent","ponBiasCurrent"); $ponStatsCached = $sendData = array(); $subId = $this->d_s; $metrics = array("rxPower" => "{$subId}_pon_rx_", "txPower" => "{$subId}_pon_tx_", "temperature" => "{$subId}_pon_temperature_", "voltage" => "{$subId}_pon_voltage_", "biasCurrent" => "{$subId}_pon_biascurrent_"); foreach($dataCached as $index => $pon) { $ponPort = $index; $stats = array(); $stats['ponPort'] = "{$pon['slot']}/{$pon['port']}"; foreach($metrics as $data => $metric) { if(isset($$data[$index]) && !empty($$data[$index])) { $m = "{$metric}{$ponPort}"; $v = $$data[$index]; if($data == "rxPower") { $stats[$data] = array(0 => $v); } else { $stats[$data] = $v; } $sendData[$m] = "{$v}|g"; } } $ponStatsCached[$index] = $stats; } if($ponStatsCached) { $key_pon_stats = "olt_stats_pons_{$this->d_s}"; $this->setData($key_pon_stats, $ponStatsCached, 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"); } }