|
@@ -1,29 +1,33 @@
|
|
|
<?php
|
|
|
+# bin/console cmts:cm:stats --cmts-device-id=14 --cmts-server-id=1 --cm-ip=10.42.0.27 --cm-mac=00237406d524 --cm-community=public
|
|
|
+# http://200.50.168.115/Provisioning/admin/cablemodem/00237406d524
|
|
|
|
|
|
namespace CmtsBundle\Command;
|
|
|
|
|
|
-use BaseStatsBundle\Command\BaseCmtsCommand;
|
|
|
+use BaseStatsBundle\Command\BaseCmCommand;
|
|
|
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 CmtsBundle\SNMP\SNMP as SNMP;
|
|
|
|
|
|
-class CmtsCmStatsCommand extends BaseCmtsCommand
|
|
|
+class CmtsCmStatsCommand extends BaseCmCommand
|
|
|
{
|
|
|
|
|
|
protected function configure()
|
|
|
{
|
|
|
$this
|
|
|
->setName('cmts:cm:stats')
|
|
|
- ->setDescription('Escanear CMTS para obtener CMs')
|
|
|
+ ->setDescription('Obtener estadísticas de un CM')
|
|
|
->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
|
|
|
->setDefinition(array(
|
|
|
new InputOption('cmts-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId del CMTS",1),
|
|
|
new InputOption('cmts-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice del CMTS",1),
|
|
|
- new InputOption('cmts-ip', false, InputOption::VALUE_OPTIONAL, "IP del CMTS"),
|
|
|
- new InputOption('cmts-community', false, InputOption::VALUE_OPTIONAL, "Community del CMTS"),
|
|
|
- new InputOption('cmts-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP")
|
|
|
+ new InputOption('cm-ip', false, InputOption::VALUE_OPTIONAL, "IP del CM"),
|
|
|
+ new InputOption('cm-mac', false, InputOption::VALUE_OPTIONAL, "MAC del CM"),
|
|
|
+ new InputOption('cm-community', false, InputOption::VALUE_OPTIONAL, "Community del CMTS",'public'),
|
|
|
+ new InputOption('cm-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP",'OIDSBase'),
|
|
|
+ new InputOption('save-historic', null, InputOption::VALUE_OPTIONAL, "Send data to StatsD",1)
|
|
|
))
|
|
|
;
|
|
|
}
|
|
@@ -36,49 +40,67 @@ class CmtsCmStatsCommand extends BaseCmtsCommand
|
|
|
{
|
|
|
parent::execute($input, $output);
|
|
|
|
|
|
- $key_cmts_scan = "cmts_scan_{$this->d_s}";
|
|
|
- $inicio = microtime(true);
|
|
|
|
|
|
- $SNMP = new SNMP($this->cmtsIp, $this->cmtsCommunity);
|
|
|
- $library = "use".$this->cmtsSnmpLibrary;
|
|
|
- $this->apiSNMP = $SNMP->$library();
|
|
|
-
|
|
|
- $dataCached = array();
|
|
|
- $countCms = 0;
|
|
|
-
|
|
|
- $macs = $this->getSNMP("docsIfCmtsCmStatusMacAddress","cmMac");
|
|
|
- $ips = $this->getSNMP("docsIfCmtsCmStatusIpAddress","cmIp");
|
|
|
- $status = $this->getSNMP("docsIfCmtsCmStatusValue","cmStatus");
|
|
|
+ $key_cm_stats = "cm_stats_{$this->d_s}"; // group by cmts
|
|
|
+ $saveHistoric = (int) $input->getOption('save-historic');
|
|
|
+ $inicio = microtime(true);
|
|
|
|
|
|
- $up = $this->getSNMP("docsIfCmtsCmStatusUpChannelIfIndex","cmUpIf");
|
|
|
- $down = $this->getSNMP("docsIfCmtsCmStatusDownChannelIfIndex","cmDownIf");
|
|
|
+ $SNMP = new SNMP($this->cmIp, $this->cmCommunity);
|
|
|
+ $SNMP->setTimeout(5000000); // 5 seconds of timeout
|
|
|
+ $SNMP->setRetry(1); // 1 query per metric
|
|
|
+ $library = "use".$this->cmSnmpLibrary;
|
|
|
+ $this->apiSNMP = $SNMP->$library();
|
|
|
+
|
|
|
+ $txPower = $this->getSNMP("docsIfCmStatusTxPower","cmTxPower");
|
|
|
+ $rxPower = $this->getSNMP("docsIfDownChannelPower","cmRxPower");
|
|
|
+ $signal = $this->getSNMP("docsIfSigQSignalNoise","cmSignal");
|
|
|
+ $microreflection = $this->getSNMP("docsIfSigQMicroreflections","cmMicroreflection");
|
|
|
+ $unerroreds = $this->getSNMP("docsIfSigQUnerroreds","cmUnerroreds");
|
|
|
+ $correcteds = $this->getSNMP("docsIfSigQCorrecteds","cmCorrecteds");
|
|
|
+ $uncorrectables = $this->getSNMP("docsIfSigQUncorrectables","cmUncorrectables");
|
|
|
+
|
|
|
+ $metrics = array('txPower' => 'cm_tx_', 'rxPower' => 'cm_rx_', 'signal' => 'cm_signal_', 'microreflection' => 'cm_microreflection_', 'unerroreds' => 'cm_unerroreds_', 'correcteds' => 'cm_correcteds_', 'uncorrectables' => 'cm_uncorrectables_');
|
|
|
+ $sendData = $data = array();
|
|
|
+
|
|
|
+ foreach($metrics as $var => $m) {
|
|
|
+
|
|
|
+ $data[$var] = array();
|
|
|
+
|
|
|
+ if(!is_array($$var)) continue;
|
|
|
+
|
|
|
+ $multiplicator = 1;
|
|
|
+ if(in_array($var, array('txPower','rxPower','signal'))) {
|
|
|
+ $multiplicator = 0.1;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($$var as $channel => $value) {
|
|
|
+ $v = $value * $multiplicator;
|
|
|
+ $_m = "{$m}{$this->cmMac}.{$channel}";
|
|
|
+ $data[$var][$channel] = $v;
|
|
|
+ $sendData[$_m] = "{$v}|g";
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- foreach($macs as $index => $mac) {
|
|
|
- $countCms++; $data = array();
|
|
|
- $data['mac'] = strtolower($mac);
|
|
|
- (isset($ips[$index]))? $data['ip'] = $ips[$index] : $data['ip'] = null;
|
|
|
-
|
|
|
- /* $values = array(1 => 'other', 2 => 'ranging',
|
|
|
- 3 => 'rangingAborted', 4 => 'rangingComplete',
|
|
|
- 5 => 'ipComplete', 6 => 'registrationComplete', 7 => 'accessDenied'); */
|
|
|
- (isset($status[$index]) && ($status[$index] == 6))? $data['status'] = 1 : $data['status'] = 0;
|
|
|
+ $this->hset($key_cm_stats, $this->cmMac, $data, true);
|
|
|
|
|
|
- (isset($up[$index]))? $data['upInterface'] = $up[$index] : $data['upInterface'] = null;
|
|
|
- (isset($down[$index]))? $data['downInterface'] = $down[$index] : $data['downInterface'] = null;
|
|
|
+ //$data = $this->collector->hgetall($key_cm_stats);
|
|
|
|
|
|
- $dataCached[$index] = $data;
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
- $this->setData($key_cmts_scan, $dataCached, true);
|
|
|
-
|
|
|
- /* Fin de bloqueo */
|
|
|
+ /* End Of Blockout */
|
|
|
$this->removeLock($this->flag);
|
|
|
|
|
|
$fin = microtime(true);
|
|
|
$time = $fin - $inicio;
|
|
|
- $this->output->writeln("Tiempo: $time segundos / Cantidad CMs: {$countCms}");
|
|
|
-
|
|
|
+ $this->output->writeln("Tiempo: $time segundos");
|
|
|
}
|
|
|
|
|
|
}
|