|
@@ -0,0 +1,137 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace FiberhomeBundle\Command;
|
|
|
+
|
|
|
+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 FiberhomeBundle\SNMP\SNMP as SNMP;
|
|
|
+//use RedisBundle\Services\RedisService;
|
|
|
+
|
|
|
+class FiberhomePonOctetsCommand extends BaseCommand
|
|
|
+{
|
|
|
+
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ $this
|
|
|
+ ->setName('fiberhome:pon:octets')
|
|
|
+ ->setDescription('Bandwidth 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_octets_d_{$oltDeviceId}_s_{$oltServerId}.lock";
|
|
|
+ $key_olt_scan = "olt_scan_pons_d_{$oltDeviceId}_s_{$oltServerId}";
|
|
|
+ $key_olt_pon_bandwidth = "olt_bandwidth_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);
|
|
|
+ $bandwidthCached = $this->getData($key_olt_pon_bandwidth, true);
|
|
|
+
|
|
|
+ if(empty($dataCached)) {
|
|
|
+ $this->output->writeln("Se requiere {$key_olt_scan}.");
|
|
|
+ $this->removeLock($flag);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //counter64
|
|
|
+ $inOctets = $SNMP->$library()->ifHCInOctets();
|
|
|
+ $outOctets = $SNMP->$library()->ifHCOutOctets();
|
|
|
+
|
|
|
+ $sendData = array();
|
|
|
+
|
|
|
+ $subId = "d_{$oltDeviceId}_s_{$oltServerId}";
|
|
|
+
|
|
|
+ $t1 = time();
|
|
|
+ foreach($dataCached as $index => $pon) {
|
|
|
+ $ponPort = "{$pon['slot']}.{$pon['port']}";
|
|
|
+
|
|
|
+ //foreach($metrics as $data => $metric) {
|
|
|
+ //if(isset($$data[$index]) && !empty($$data[$index])) {
|
|
|
+
|
|
|
+ (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;
|
|
|
+ }
|
|
|
+
|
|
|
+ $sendData["{$subId}_inbandwidth_pon_{$ponPort}"] = "{$inBandwidth}|g";
|
|
|
+ $sendData["{$subId}_outbandwidth_pon_{$ponPort}"] = "{$outBandwidth}|g";
|
|
|
+
|
|
|
+ $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' => $in1, 'outAcc' => $out1, 'inBand' => 0, 'outBand' => 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $this->collector->set($key_olt_pon_bandwidth, $bandwidthCached, 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");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|