|
@@ -60,14 +60,14 @@ class HuaweiOnuOctetsCommand extends BaseCommand
|
|
$inOctets = $this->getSNMP("onuInOctets","onuInOctets");
|
|
$inOctets = $this->getSNMP("onuInOctets","onuInOctets");
|
|
$outOctets = $this->getSNMP("onuOutOctets","onuOutOctets");
|
|
$outOctets = $this->getSNMP("onuOutOctets","onuOutOctets");
|
|
|
|
|
|
- $sendData = array();
|
|
|
|
|
|
+ $consumptionData = $sendData = array();
|
|
|
|
|
|
$subId = $this->d_s;
|
|
$subId = $this->d_s;
|
|
|
|
|
|
$t1 = time();
|
|
$t1 = time();
|
|
$totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
|
|
$totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
|
|
foreach($dataCached as $index => $onu) {
|
|
foreach($dataCached as $index => $onu) {
|
|
-
|
|
|
|
|
|
+ $inDiff = $outDiff = 0;
|
|
$sn = $onu["serialNumber"];
|
|
$sn = $onu["serialNumber"];
|
|
|
|
|
|
(isset($inOctets[$index]))? $in1 = $inOctets[$index] : $in1 = 0;
|
|
(isset($inOctets[$index]))? $in1 = $inOctets[$index] : $in1 = 0;
|
|
@@ -83,13 +83,13 @@ class HuaweiOnuOctetsCommand extends BaseCommand
|
|
$inBandwidth = $outBandwidth = 0;
|
|
$inBandwidth = $outBandwidth = 0;
|
|
|
|
|
|
if(($in1 >= $in0) && ($t1 > $t0)) {
|
|
if(($in1 >= $in0) && ($t1 > $t0)) {
|
|
- $diff = $in1 - $in0;
|
|
|
|
|
|
+ $inDiff = $diff = $in1 - $in0;
|
|
$inAcc += $diff;
|
|
$inAcc += $diff;
|
|
$inBandwidth = ($diff / ($t1 - $t0)) * 8;
|
|
$inBandwidth = ($diff / ($t1 - $t0)) * 8;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if(($out1 >= $out0) && ($t1 > $t0)) {
|
|
if(($out1 >= $out0) && ($t1 > $t0)) {
|
|
- $diff = $out1 - $out0;
|
|
|
|
|
|
+ $outDiff = $diff = $out1 - $out0;
|
|
$outAcc += $diff;
|
|
$outAcc += $diff;
|
|
$outBandwidth = ($diff / ($t1 - $t0)) * 8;
|
|
$outBandwidth = ($diff / ($t1 - $t0)) * 8;
|
|
}
|
|
}
|
|
@@ -101,13 +101,23 @@ class HuaweiOnuOctetsCommand extends BaseCommand
|
|
$sendData["outbandwidth_onu_{$sn}"] = "{$outBandwidth}|g";
|
|
$sendData["outbandwidth_onu_{$sn}"] = "{$outBandwidth}|g";
|
|
|
|
|
|
$div = 1073741824; //bytes => giga
|
|
$div = 1073741824; //bytes => giga
|
|
- $consIn = number_format(($inAcc / $div),3);
|
|
|
|
- $consOut = number_format(($outAcc / $div),3);
|
|
|
|
|
|
+ $consIn = number_format(($inAcc / $div),3,'.','');
|
|
|
|
+ $consOut = number_format(($outAcc / $div),3,'.','');
|
|
|
|
|
|
$sendData["inconsumption_onu_{$sn}"] = "{$consIn}|g";
|
|
$sendData["inconsumption_onu_{$sn}"] = "{$consIn}|g";
|
|
$sendData["outconsumption_onu_{$sn}"] = "{$consOut}|g";
|
|
$sendData["outconsumption_onu_{$sn}"] = "{$consOut}|g";
|
|
|
|
|
|
- if(date("d",$t0) != date("d",$t1)) {
|
|
|
|
|
|
+ $div = 1073741824; //bytes => giga
|
|
|
|
+ $inGB = number_format($inDiff / $div, 5,".","");
|
|
|
|
+ $outGB = number_format($outDiff / $div, 5,".","");
|
|
|
|
+ $server = $this->oltServerId;
|
|
|
|
+ $fatherDevice = $this->oltDeviceId;
|
|
|
|
+ $fatherDeviceType = 2;
|
|
|
|
+ $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;
|
|
$inAcc = $outAcc = 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -120,7 +130,10 @@ class HuaweiOnuOctetsCommand extends BaseCommand
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
$this->setData($key_olt_onu_bandwidth, $bandwidthCached, true);
|
|
$this->setData($key_olt_onu_bandwidth, $bandwidthCached, true);
|
|
|
|
+
|
|
|
|
+ $this->saveConsumption($consumptionData);
|
|
|
|
|
|
if($sendData && $saveHistoric) {
|
|
if($sendData && $saveHistoric) {
|
|
$t_start_script = microtime(true);
|
|
$t_start_script = microtime(true);
|
|
@@ -140,4 +153,16 @@ class HuaweiOnuOctetsCommand 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));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|