Pārlūkot izejas kodu

Se añade consumo para star en el nas

Maxi Schvindt 7 gadi atpakaļ
vecāks
revīzija
7a8869b2c2
1 mainītis faili ar 28 papildinājumiem un 4 dzēšanām
  1. 28 4
      Command/NasOnuOctetsCommand.php

+ 28 - 4
Command/NasOnuOctetsCommand.php

@@ -87,7 +87,7 @@ class NasOnuOctetsCommand extends BaseCommand
         $inOctets = $this->getSNMP("onuInOctets","onuInOctets");
         $outOctets = $this->getSNMP("onuOutOctets","onuOutOctets");
 
-        $sendData = array();
+        $consumptionData = $sendData = array();
         
         $subId = $this->d_s;
         
@@ -111,16 +111,16 @@ class NasOnuOctetsCommand extends BaseCommand
                 $inAcc = $bandwidthCached[$index]['inAcc'];
                 $outAcc = $bandwidthCached[$index]['outAcc'];
 
-                $inBandwidth = $outBandwidth = 0; 
+                $inDiff = $outDiff = $inBandwidth = $outBandwidth = 0; 
                  
                 if(($in1 >= $in0) && ($t1 > $t0)) {
-                    $diff = $in1 - $in0;
+                    $inDiff = $diff = $in1 - $in0;
                     $inAcc += $diff;
                     $inBandwidth = ($diff / ($t1 - $t0)) * 8;
                 }
 
                 if(($out1 >= $out0) && ($t1 > $t0)) {
-                    $diff = $out1 - $out0;
+                    $outDiff = $diff = $out1 - $out0;
                     $outAcc += $diff;
                     $outBandwidth = ($diff / ($t1 - $t0)) * 8;
                 }
@@ -138,6 +138,16 @@ class NasOnuOctetsCommand extends BaseCommand
                 $sendData["inconsumption_onu_{$sn}"] = "{$consIn}|g";
                 $sendData["outconsumption_onu_{$sn}"] = "{$consOut}|g";
 
+                $div = 1073741824; //bytes => giga
+                $inGB =  number_format($inDiff / $div, 5,".","");
+                $outGB = number_format($outDiff / $div, 5,".","");
+                $fatherDevice = $this->nasDeviceId;
+                $server = $this->nasServerId;
+                $fatherDeviceType = 3;
+                $device = $sn;
+                $date = date("Y-m-d");
+                $consumptionData[] = "({$server},{$fatherDevice},{$fatherDeviceType},'{$device}','{$date}',{$inGB},{$outGB})";
+
                 if(date("n",$t0) != date("n",$t1)) {
                     $inAcc = $outAcc = 0;
                 }
@@ -154,6 +164,8 @@ class NasOnuOctetsCommand extends BaseCommand
 
         $this->setData($key_nas_onu_bandwidth, $bandwidthCached, true);
 
+        $this->saveConsumption($consumptionData);
+
         if($sendData && $saveHistoric) {
             $t_start_script = microtime(true); 
             $statsdService = $this->getContainer()->get('statsd');
@@ -214,4 +226,16 @@ class NasOnuOctetsCommand extends BaseCommand
 
     }
 
+    /**
+     * @param array $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));
+            
+        }
+    }
+
 }