|
@@ -0,0 +1,158 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace FiberlinkBundle\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 FiberlinkBundle\SNMP\SNMP as SNMP;
|
|
|
+//use RedisBundle\Services\RedisService;
|
|
|
+
|
|
|
+class FiberlinkPonOctetsCommand extends BaseCommand
|
|
|
+{
|
|
|
+
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ $this
|
|
|
+ ->setName('fiberlink: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"),
|
|
|
+ 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);
|
|
|
+
|
|
|
+ $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');
|
|
|
+ $saveHistoric = (int) $input->getOption('save-historic');
|
|
|
+
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+
|
|
|
+ $ifDescr = $SNMP->$library()->ifDescr();
|
|
|
+ $inverse = $interfaces = array();
|
|
|
+ foreach($ifDescr as $index => $d) {
|
|
|
+ if (preg_match("/p/i", $d)) {
|
|
|
+ $s = str_replace(array("p","P"," "),"",$d);
|
|
|
+ $s_p = explode("/",trim($s));
|
|
|
+ if(count($s_p) == 2) {
|
|
|
+ $s = $s_p[0];
|
|
|
+ $p = $s_p[1];
|
|
|
+ $interfaces[$index] = array("ponPort"=>"{$s}.{$p}",'slot'=>$s,'port'=>$p);
|
|
|
+ $inverse["{$s}.{$p}"] = $index;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //counter64
|
|
|
+ $inOctets = $SNMP->$library()->ifHCInOctets();
|
|
|
+ $outOctets = $SNMP->$library()->ifHCOutOctets();
|
|
|
+
|
|
|
+ $sendData = array();
|
|
|
+
|
|
|
+ $subId = "d_{$oltDeviceId}_s_{$oltServerId}";
|
|
|
+
|
|
|
+ $t1 = time();
|
|
|
+ foreach($dataCached as $index => $pon) {
|
|
|
+ $ponPort = $index;
|
|
|
+ if(!isset($inverse[$index])) continue;
|
|
|
+
|
|
|
+ $inverseIndex = $inverse[$index];
|
|
|
+
|
|
|
+ //foreach($metrics as $data => $metric) {
|
|
|
+ //if(isset($$data[$index]) && !empty($$data[$index])) {
|
|
|
+
|
|
|
+ (isset($inOctets[$inverseIndex]))? $in1 = $inOctets[$inverseIndex] : $in1 = 0;
|
|
|
+ (isset($outOctets[$inverseIndex]))? $out1 = $outOctets[$inverseIndex] : $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->setData($key_olt_pon_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($flag);
|
|
|
+
|
|
|
+ $fin = microtime(true);
|
|
|
+ $time = $fin - $inicio;
|
|
|
+ $this->output->writeln("Tiempo: $time segundos");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|