|
@@ -4,6 +4,7 @@
|
|
namespace Flowdat\Stats\App\Service\Zte;
|
|
namespace Flowdat\Stats\App\Service\Zte;
|
|
|
|
|
|
|
|
|
|
|
|
+use Flowdat\Stats\App\Helper\OnuHelper;
|
|
use Flowdat\Stats\App\Helper\RedisHelper;
|
|
use Flowdat\Stats\App\Helper\RedisHelper;
|
|
use Flowdat\Stats\App\Service\SNMP\SNMPService;
|
|
use Flowdat\Stats\App\Service\SNMP\SNMPService;
|
|
use Flowdat\Stats\App\Service\StatsD\StatsDService;
|
|
use Flowdat\Stats\App\Service\StatsD\StatsDService;
|
|
@@ -233,4 +234,215 @@ class ZteService
|
|
$this->output->writeln("Tiempo: $time segundos");
|
|
$this->output->writeln("Tiempo: $time segundos");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function searchNumberSerialAndSaveCache($keyOltScan, $keyOltPons){
|
|
|
|
+ $startCmd = microtime(true);
|
|
|
|
+
|
|
|
|
+ $serialNumbersCached = $this->redisHelper->getData($keyOltScan);
|
|
|
|
+ $portCached = $this->redisHelper->getData($keyOltPons, true);
|
|
|
|
+
|
|
|
|
+ if(!empty($serialNumbersCached)){
|
|
|
|
+ $endCmd = microtime(true);
|
|
|
|
+ $time = $endCmd - $startCmd;
|
|
|
|
+ $countOnusCached = count($serialNumbersCached);
|
|
|
|
+ $this->output->writeln("Tiempo: $time segundos / Cantidad ONUs: {$countOnusCached}");
|
|
|
|
+
|
|
|
|
+ return $this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $serialNumbers = $this->snmpService->getSNMP($this->snmpLibrary, "onuSerialNumber","onuScan", $this->output);
|
|
|
|
+ $countOnus = 0;
|
|
|
|
+ $serialNumbersCached = [];
|
|
|
|
+
|
|
|
|
+ foreach($serialNumbers as $index => $hexSerialNumber) {
|
|
|
|
+ $vendoId = OnuHelper::hex2str(substr($hexSerialNumber,0,8));
|
|
|
|
+ $rest = substr($hexSerialNumber,8);
|
|
|
|
+
|
|
|
|
+ $sn = strtolower($vendoId.$rest);
|
|
|
|
+
|
|
|
|
+ $portOnu = explode(".",$index);
|
|
|
|
+ if(count($portOnu) != 2) continue;
|
|
|
|
+ $portIndex = $portOnu[0];
|
|
|
|
+ $onuId = $portOnu[1];
|
|
|
|
+ $countOnus++;
|
|
|
|
+
|
|
|
|
+ if(isset($portCached[$portIndex])) {
|
|
|
|
+ $p = $portCached[$portIndex];
|
|
|
|
+
|
|
|
|
+ $data = $p;
|
|
|
|
+ $data['onuId'] = $onuId;
|
|
|
|
+ $data['serialNumber'] = $sn;
|
|
|
|
+ $data['hexaSerialNumber'] = $hexSerialNumber;
|
|
|
|
+ $data['ponport'] = "{$p['ponPort']}/{$onuId}";
|
|
|
|
+ $serialNumbersCached[$index] = $data;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->redisHelper->setData($keyOltScan, $serialNumbersCached, true);
|
|
|
|
+
|
|
|
|
+ $endCmd = microtime(true);
|
|
|
|
+ $time = $endCmd - $startCmd;
|
|
|
|
+ $this->output->writeln("Tiempo: $time segundos / Cantidad ONUs: {$countOnus}");
|
|
|
|
+
|
|
|
|
+ return $this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function searchInformationsAboutOnuAndSave($keyOltScan, $keyOltPonBandwith, $subId, $saveHistoric){
|
|
|
|
+ $startCmd = microtime(true);
|
|
|
|
+ $serialNumberCache = $this->redisHelper->getData($keyOltScan, true);
|
|
|
|
+
|
|
|
|
+ if(!empty($serialNumberCache)){
|
|
|
|
+ $txPower = $this->snmpService->getSNMP($this->snmpLibrary, "onuPonTxOpticalPower","onuTxPower", $this->output);
|
|
|
|
+ $rxPower = $this->snmpService->getSNMP($this->snmpLibrary,"onuPonRxOpticalPower","onuRxPower", $this->output);
|
|
|
|
+ $temperature = $this->snmpService->getSNMP($this->snmpLibrary,"onuPonOpticalTemperature","onuTemperature", $this->output);
|
|
|
|
+ $voltage = $this->snmpService->getSNMP($this->snmpLibrary,"onuPonOpticalVltage","onuVoltage", $this->output);
|
|
|
|
+ $status = $this->snmpService->getSNMP($this->snmpLibrary,"onuStatus","onuStatus", $this->output);
|
|
|
|
+ //counter64
|
|
|
|
+ $inOctets = $this->snmpService->getSNMP($this->snmpLibrary, "ifHCInOctets","portInOctets", $this->output);
|
|
|
|
+ $outOctets = $this->snmpService->getSNMP($this->snmpLibrary, "ifHCOutOctets","portOutOctets", $this->output);
|
|
|
|
+
|
|
|
|
+ $stats = $sendData = array();
|
|
|
|
+
|
|
|
|
+ $metrics = array("txPower" => "onu_tx_", "rxPower" => "onu_rx_", "temperature" => "onu_temperature_", "voltage" => "onu_voltage_", "status" => "onu_status_");
|
|
|
|
+
|
|
|
|
+ foreach($metrics as $m => $metric) {
|
|
|
|
+ $stats[$metric] = array();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $bandwidthCached = $this->redisHelper->getData($keyOltPonBandwith, true);
|
|
|
|
+
|
|
|
|
+ $totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
|
|
|
|
+ foreach($serialNumberCache as $index => $onu) {
|
|
|
|
+ $statusIndex = $index;
|
|
|
|
+ $index = $index.".1";
|
|
|
|
+ $sn = strtolower($onu['serialNumber']);
|
|
|
|
+
|
|
|
|
+ foreach($metrics as $data => $metric) {
|
|
|
|
+
|
|
|
|
+ $m = "{$metric}{$sn}";
|
|
|
|
+ if(isset($$data[$index]) && !empty($$data[$index])) {
|
|
|
|
+
|
|
|
|
+ if($data == 'txPower') {
|
|
|
|
+ $v = $$data[$index] * 0.002 - 30;
|
|
|
|
+ } elseif($data == "rxPower") {
|
|
|
|
+ $v = $$data[$index] * 0.002 - 30;
|
|
|
|
+ } elseif($data == "voltage") {
|
|
|
|
+ $v = ($$data[$index] * 20) / 1000;
|
|
|
|
+ } elseif ($data == "temperature") {
|
|
|
|
+ $v = $$data[$index] / 256;
|
|
|
|
+ } else {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $sendData[$m] = "{$v}|g";
|
|
|
|
+
|
|
|
|
+ $stats[$metric][$sn] = $v;
|
|
|
|
+ } elseif($data == "status") {
|
|
|
|
+ $v = 0;
|
|
|
|
+ if(isset($$data[$statusIndex]) && $$data[$statusIndex] == 3) $v = 1;
|
|
|
|
+
|
|
|
|
+ $sendData[$m] = "{$v}|g";
|
|
|
|
+ $stats[$metric][$sn] = $v;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->setOltBandwith($sendData, $onu, $index, $bandwidthCached, $subId, $inOctets, $outOctets, $totalIn, $totalOut, $totalConsIn, $totalConsOut);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->redisHelper->setData($keyOltPonBandwith, $bandwidthCached, true);
|
|
|
|
+
|
|
|
|
+ $oltBandwidth = array();
|
|
|
|
+ $oltBandwidth["{$subId}_inbandwidth_olt"] = "{$totalIn}|g";
|
|
|
|
+ $oltBandwidth["{$subId}_outbandwidth_olt"] = "{$totalOut}|g";
|
|
|
|
+
|
|
|
|
+ $div = 1073741824; //bytes => giga
|
|
|
|
+ $consIn = number_format(($totalConsIn / $div),3,'.','');
|
|
|
|
+ $consOut = number_format(($totalConsOut / $div),3,'.','');
|
|
|
|
+ $oltConsumption = array();
|
|
|
|
+ $oltConsumption["{$subId}_inconsumption_olt"] = "{$consIn}|g";
|
|
|
|
+ $oltConsumption["{$subId}_outconsumption_olt"] = "{$consOut}|g";
|
|
|
|
+
|
|
|
|
+ $statsdService = new StatsDService();
|
|
|
|
+ $statsdService->send($oltBandwidth);
|
|
|
|
+ $statsdService->send($oltConsumption);
|
|
|
|
+
|
|
|
|
+ foreach($stats as $metric => $data) {
|
|
|
|
+ $keyOnuStats = "{$metric}{$subId}";
|
|
|
|
+
|
|
|
|
+ $this->redisHelper->setData($keyOnuStats, $data, true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if($sendData && $saveHistoric) {
|
|
|
|
+ $startScript = microtime(true);
|
|
|
|
+ (new StatsDService())->send($sendData);
|
|
|
|
+ $endScript = microtime(true);
|
|
|
|
+ $time = $endScript - $startScript;
|
|
|
|
+ print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: ".count($sendData).PHP_EOL);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Fin de bloqueo */
|
|
|
|
+ RedisHelper::removeLock($this->flagCmd);
|
|
|
|
+
|
|
|
|
+ $endCmd = microtime(true);
|
|
|
|
+ $time = $endCmd - $startCmd;
|
|
|
|
+ $this->output->writeln("Tiempo: $time segundos");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function setOltBandwith(&$sendData, $pon, $index, &$bandwidthCached, $subId, $inOctets, $outOctets, &$totalIn, &$totalOut, &$totalConsIn, &$totalConsOut){
|
|
|
|
+ $t1 = time();
|
|
|
|
+
|
|
|
|
+ (isset($inOctets[$index]))? $in1 = $inOctets[$index] : $in1 = 0;
|
|
|
|
+ (isset($outOctets[$index]))? $out1 = $outOctets[$index] : $out1 = 0;
|
|
|
|
+
|
|
|
|
+ $ponPort = str_replace("/",".",$pon['ponPort']);
|
|
|
|
+
|
|
|
|
+ if(isset($bandwidthCached[$index]) && !isset($pon['nexo'])) {
|
|
|
|
+ $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["{$subId}_inbandwidth_pon_{$ponPort}"] = "{$inBandwidth}|g";
|
|
|
|
+ $sendData["{$subId}_outbandwidth_pon_{$ponPort}"] = "{$outBandwidth}|g";
|
|
|
|
+
|
|
|
|
+ $div = 1073741824; //bytes => giga
|
|
|
|
+ $_in = number_format(($inAcc / $div),3,'.','');
|
|
|
|
+ $_out = number_format(($outAcc / $div),3,'.','');
|
|
|
|
+ $sendData["{$subId}_inconsumption_pon_{$ponPort}"] = "{$_in}|g";
|
|
|
|
+ $sendData["{$subId}_outconsumption_pon_{$ponPort}"] = "{$_out}|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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|