Просмотр исходного кода

Comando para consultar stats de CM.

Maxi Schvindt 7 лет назад
Родитель
Сommit
a07bd7267a
2 измененных файлов с 104 добавлено и 50 удалено
  1. 59 37
      Command/CmtsCmStatsCommand.php
  2. 45 13
      SNMP/MIBS/OIDSBase.php

+ 59 - 37
Command/CmtsCmStatsCommand.php

@@ -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");
     }
 
 }

+ 45 - 13
SNMP/MIBS/OIDSBase.php

@@ -12,6 +12,23 @@ class OIDSBase extends \CmtsBundle\SNMP\MIB {
     const OID_docsIfCmtsCmStatusUpChannelIfIndex =  "1.3.6.1.2.1.10.127.1.3.3.1.5";  //cm_index > up interface
     const OID_docsIfCmtsCmStatusDownChannelIfIndex = "1.3.6.1.2.1.10.127.1.3.3.1.4";  //cm_index > down interface
 
+    //CM
+    const OID_docsIfCmStatusTxPower = "1.3.6.1.2.1.10.127.1.2.2.1.3"; //SNMP contra CM .channelCm > TxPower (v / 10)
+    const OID_docsIfDownChannelPower = "1.3.6.1.2.1.10.127.1.1.1.1.6"; //SNMP contra CM .channelCm > RxPower (v / 10)
+    const OID_docsIfSigQSignalNoise = "1.3.6.1.2.1.10.127.1.1.4.1.5"; //SNMP contra CM .channelCm > SNR (v / 10)
+    const OID_docsIfSigQMicroreflections = "1.3.6.1.2.1.10.127.1.1.4.1.6"; //SNMP contra CM .channelCm > Microreflection (v)
+    const OID_docsIfSigQUnerroreds = "1.3.6.1.2.1.10.127.1.1.4.1.2"; //SNMP contra CM .channelCm > Unerroreds
+    const OID_docsIfSigQCorrecteds = "1.3.6.1.2.1.10.127.1.1.4.1.3"; //SNMP contra CM .channelCm > Correcteds
+    const OID_docsIfSigQUncorrectables = "1.3.6.1.2.1.10.127.1.1.4.1.4"; //SNMP contra CM .channelCm > Uncorrectables
+
+
+
+
+
+
+
+
+
     
     const OID_docsIfCmtsCmStatusSignalNoise 	= "1.3.6.1.2.1.10.127.1.3.3.1.13";  //cm_index > snr en interface
     
@@ -22,8 +39,8 @@ class OIDSBase extends \CmtsBundle\SNMP\MIB {
     const OID_if_out_octets = '1.3.6.1.2.1.2.2.1.16';  //if_index > out octets (counter32)
     
     const OID_docsIfCmtsChannelUtilization          = "1.3.6.1.2.1.10.127.1.3.9.1.3";
-    const OID_docsIfSigQMicroreflections            = "1.3.6.1.2.1.10.127.1.1.4.1.6";
-    const OID_docsIfSigQSignalNoise		            = "1.3.6.1.2.1.10.127.1.1.4.1.5";
+    //const OID_docsIfSigQMicroreflections            = "1.3.6.1.2.1.10.127.1.1.4.1.6";
+    //const OID_docsIfSigQSignalNoise		            = "1.3.6.1.2.1.10.127.1.1.4.1.5";
 
 
     const OID_docsQosCmtsIfIndex                = "1.3.6.1.2.1.10.127.7.1.11.1.3";
@@ -38,10 +55,12 @@ class OIDSBase extends \CmtsBundle\SNMP\MIB {
     const docsIfCmtsChannelUtilization          = "1.3.6.1.2.1.10.127.1.3.9.1.3";
     const OID_ipNetToMediaPhysAddress 		= "1.3.6.1.2.1.4.22.1.2";
     const OID_docsIfCmtsCmPtr  			= "1.3.6.1.2.1.10.127.1.3.7.1.2";
-    const OID_docsIfCmStatusTxPower 		= "1.3.6.1.2.1.10.127.1.2.2.1.3";
+    
+    //const OID_docsIfCmStatusTxPower 		= "1.3.6.1.2.1.10.127.1.2.2.1.3";
     const OID_docsIfDownChannelFrequency	= "1.3.6.1.2.1.10.127.1.1.1.1.2";
     const OID_docsIfDownChannelModulation       = "1.3.6.1.2.1.10.127.1.1.1.1.4";
-    const OID_docsIfDownChannelPower		= "1.3.6.1.2.1.10.127.1.1.1.1.6";
+   
+   // const OID_docsIfDownChannelPower		= "1.3.6.1.2.1.10.127.1.1.1.1.6";
     const OID_docsIfUpChannelFrequency		= "1.3.6.1.2.1.10.127.1.1.2.1.2";
     const OID_docsIfUpChannelWidth 		= "1.3.6.1.2.1.10.127.1.1.2.1.3";
     
@@ -79,14 +98,6 @@ class OIDSBase extends \CmtsBundle\SNMP\MIB {
         return $this->getSNMP()->lastOidWalk(self::OID_docsIfCmtsChannelUtilization,14);
     }
     
-    public function docsIfSigQMicroreflections() {
-        return $this->getSNMP()->lastOidWalk(self::OID_docsIfSigQMicroreflections,14);
-    }
-    
-    public function docsIfSigQSignalNoise() {
-        return $this->getSNMP()->lastOidWalk(self::OID_docsIfSigQSignalNoise,14);
-    }
-    
     public function inOctets() {
         return $this->getSNMP()->lastOidWalk(self::OID_if_in_octets,11);
     }
@@ -95,6 +106,27 @@ class OIDSBase extends \CmtsBundle\SNMP\MIB {
         return $this->getSNMP()->lastOidWalk(self::OID_if_out_octets,11);
     }
 
-    
+    //SNMP sobre CM ip
+    public function docsIfCmStatusTxPower() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfCmStatusTxPower,14);
+    }
+    public function docsIfDownChannelPower() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfDownChannelPower,14);
+    }
+    public function docsIfSigQSignalNoise() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfSigQSignalNoise,14);
+    }
+    public function docsIfSigQMicroreflections() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfSigQMicroreflections,14);
+    }
+    public function docsIfSigQUnerroreds() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfSigQUnerroreds,14);
+    }
+    public function docsIfSigQCorrecteds() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfSigQCorrecteds,14);
+    }
+    public function docsIfSigQUncorrectables() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfSigQUncorrectables,14);
+    }
     
 }