Преглед на файлове

Se añade consumo a la interface. Se agrega almacenamiento de octetos en DB por día para módulo STAR.

Maxi Schvindt преди 6 години
родител
ревизия
eab8650374
променени са 3 файла, в които са добавени 40 реда и са изтрити 3 реда
  1. 2 0
      Command/CmtsCmStatsCommand.php
  2. 8 0
      Command/CmtsInterfaceStatsCommand.php
  3. 30 3
      Command/CmtsOctetsCommand.php

+ 2 - 0
Command/CmtsCmStatsCommand.php

@@ -65,6 +65,8 @@ class CmtsCmStatsCommand extends BaseCmCommand
             
             foreach($cablemodems as $dupla) {
                 list($ip, $mac) = explode(",",$dupla);
+                $this->cmIp = $ip;
+                $this->cmMac = $mac;
                 $metrics = $this->metrics($key_cm_stats, $ip, $mac);
                 $count++;
                 if($metrics && $saveHistoric) $this->sendData($metrics, $statsdService);

+ 8 - 0
Command/CmtsInterfaceStatsCommand.php

@@ -217,6 +217,14 @@ class CmtsInterfaceStatsCommand extends BaseCmtsCommand
                 $sendData["{$subId}_inbandwidth_if_{$index}"] = "{$inBandwidth}|g";
                 $sendData["{$subId}_outbandwidth_if_{$index}"] = "{$outBandwidth}|g";
 
+                // Consumo en giga
+                $div = 1073741824; //bytes => giga
+                $_consIn = number_format(($inAcc / $div),3,'.','');
+                $_consOut = number_format(($outAcc / $div),3,'.','');
+                $sendData["{$subId}_inconsumption_if_{$index}"] = "{$_consIn}|g";
+                $sendData["{$subId}_outconsumption_if_{$index}"] = "{$_consOut}|g";
+
+                // Reinicio mensual
                 if(date("n",$t0) != date("n",$t1)) {
                     $inAcc = $outAcc = 0;
                 }

+ 30 - 3
Command/CmtsOctetsCommand.php

@@ -84,13 +84,13 @@ class CmtsOctetsCommand extends BaseCmtsCommand
         
         //Flow Direction: 1 = download(in) / 2 = upload(out)
 
-        $data = array();
+        $consumptionData = $data = array();
         $totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
 
         foreach($index as $mac => $_flows) {
 
             $new = array('flows' => array());
-            $inBand = $outBand = 0;
+            $inDiff = $outDiff = $inBand = $outBand = 0;
 
             $flowsCached = array();
             if(isset($cmOctetsCached[$mac])) {
@@ -115,13 +115,16 @@ class CmtsOctetsCommand extends BaseCmtsCommand
                     if($d == 1) {
                         $band = "inBand";
                         $acc = "inAcc";
+                        $_d = "inDiff";
                     } else {
                         $band = "outBand";
                         $acc = "outAcc";
+                        $_d = "outDiff";
                     }
                         
                     if(($o1 >= $o0) && ($t1 > $t0)) {
                         $diff = $o1 - $o0;
+                        $$_d += $diff;
                         $$acc += $diff;
                         $$band += ($diff / ($t1 - $t0)) * 8;
                     }
@@ -136,6 +139,16 @@ class CmtsOctetsCommand extends BaseCmtsCommand
             $div = 1073741824; //bytes => giga
             $consIn = number_format(($inAcc / $div),3,'.','');
             $consOut = number_format(($outAcc / $div),3,'.','');
+
+            $div = 1073741824; //bytes => giga
+            $inGB =  number_format($inDiff / $div, 5,".","");
+            $outGB = number_format($outDiff / $div, 5,".","");
+            $server = $this->cmtsServerId;
+            $fatherDevice = $this->cmtsDeviceId;
+            $fatherDeviceType = 1;
+            $device = $mac;
+            $date = date("Y-m-d");
+            $consumptionData[] = "({$server},{$fatherDevice},{$fatherDeviceType},'{$device}','{$date}',{$inGB},{$outGB})";
             
             $sendData["inconsumption_cm_{$mac}"] = "{$consIn}|g";
             $sendData["outconsumption_cm_{$mac}"] = "{$consOut}|g";
@@ -171,6 +184,8 @@ class CmtsOctetsCommand extends BaseCmtsCommand
         $sendData["{$this->d_s}_inconsumption_cmts_x_cm"] = "{$consIn}|g";
         $sendData["{$this->d_s}_outconsumption_cmts_x_cm"] = "{$consOut}|g";
 
+        $this->saveConsumption($consumptionData);
+
         if($sendData && $saveHistoric) {
             $t_start_script = microtime(true); 
             $statsdService = $this->getContainer()->get('statsd');
@@ -187,6 +202,18 @@ class CmtsOctetsCommand extends BaseCmtsCommand
         $fin = microtime(true);
         $time = $fin - $inicio;
         $this->output->writeln("Tiempo: $time segundos");
+        
+    }
+    
+    /**
+     * @param array $unique_data
+     */
+    function saveConsumption($data)
+    {
+        if ($data) {
+            $query = "INSERT LOW_PRIORITY INTO `device_consumption` (`server_id`, `father_device_id`, `father_device_type`, `device`, `date`,`cons_in`,`cons_out`) VALUES " . implode(",", $data) . " ON DUPLICATE KEY UPDATE cons_out = cons_out + VALUES(cons_out), cons_in = cons_in + VALUES(cons_in);";
+            $this->executeQueries(array($query));
+            
+        }
     }
-
 }