|
@@ -84,13 +84,13 @@ class CmtsOctetsCommand extends BaseCmtsCommand
|
|
|
|
|
|
//Flow Direction: 1 = download(in) / 2 = upload(out)
|
|
//Flow Direction: 1 = download(in) / 2 = upload(out)
|
|
|
|
|
|
- $data = array();
|
|
|
|
|
|
+ $consumptionData = $data = array();
|
|
$totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
|
|
$totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
|
|
|
|
|
|
foreach($index as $mac => $_flows) {
|
|
foreach($index as $mac => $_flows) {
|
|
|
|
|
|
$new = array('flows' => array());
|
|
$new = array('flows' => array());
|
|
- $inBand = $outBand = 0;
|
|
|
|
|
|
+ $inDiff = $outDiff = $inBand = $outBand = 0;
|
|
|
|
|
|
$flowsCached = array();
|
|
$flowsCached = array();
|
|
if(isset($cmOctetsCached[$mac])) {
|
|
if(isset($cmOctetsCached[$mac])) {
|
|
@@ -115,13 +115,16 @@ class CmtsOctetsCommand extends BaseCmtsCommand
|
|
if($d == 1) {
|
|
if($d == 1) {
|
|
$band = "inBand";
|
|
$band = "inBand";
|
|
$acc = "inAcc";
|
|
$acc = "inAcc";
|
|
|
|
+ $_d = "inDiff";
|
|
} else {
|
|
} else {
|
|
$band = "outBand";
|
|
$band = "outBand";
|
|
$acc = "outAcc";
|
|
$acc = "outAcc";
|
|
|
|
+ $_d = "outDiff";
|
|
}
|
|
}
|
|
|
|
|
|
if(($o1 >= $o0) && ($t1 > $t0)) {
|
|
if(($o1 >= $o0) && ($t1 > $t0)) {
|
|
$diff = $o1 - $o0;
|
|
$diff = $o1 - $o0;
|
|
|
|
+ $$_d += $diff;
|
|
$$acc += $diff;
|
|
$$acc += $diff;
|
|
$$band += ($diff / ($t1 - $t0)) * 8;
|
|
$$band += ($diff / ($t1 - $t0)) * 8;
|
|
}
|
|
}
|
|
@@ -136,6 +139,16 @@ class CmtsOctetsCommand extends BaseCmtsCommand
|
|
$div = 1073741824; //bytes => giga
|
|
$div = 1073741824; //bytes => giga
|
|
$consIn = number_format(($inAcc / $div),3,'.','');
|
|
$consIn = number_format(($inAcc / $div),3,'.','');
|
|
$consOut = number_format(($outAcc / $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["inconsumption_cm_{$mac}"] = "{$consIn}|g";
|
|
$sendData["outconsumption_cm_{$mac}"] = "{$consOut}|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}_inconsumption_cmts_x_cm"] = "{$consIn}|g";
|
|
$sendData["{$this->d_s}_outconsumption_cmts_x_cm"] = "{$consOut}|g";
|
|
$sendData["{$this->d_s}_outconsumption_cmts_x_cm"] = "{$consOut}|g";
|
|
|
|
|
|
|
|
+ $this->saveConsumption($consumptionData);
|
|
|
|
+
|
|
if($sendData && $saveHistoric) {
|
|
if($sendData && $saveHistoric) {
|
|
$t_start_script = microtime(true);
|
|
$t_start_script = microtime(true);
|
|
$statsdService = $this->getContainer()->get('statsd');
|
|
$statsdService = $this->getContainer()->get('statsd');
|
|
@@ -187,6 +202,18 @@ class CmtsOctetsCommand extends BaseCmtsCommand
|
|
$fin = microtime(true);
|
|
$fin = microtime(true);
|
|
$time = $fin - $inicio;
|
|
$time = $fin - $inicio;
|
|
$this->output->writeln("Tiempo: $time segundos");
|
|
$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));
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|