Skip to content

Commit

Permalink
Refactor Bandwidth.
Browse files Browse the repository at this point in the history
Refactor bandwidth so its back to purely jquery request and processing.
Now that time is subjective it should remain valid even when a node goes down.
  • Loading branch information
mastacontrola committed Dec 31, 2016
1 parent 7c46a12 commit be69d85
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 67 deletions.
2 changes: 1 addition & 1 deletion packages/web/lib/fog/system.class.php
Expand Up @@ -53,7 +53,7 @@ private static function _versionCompare()
public function __construct()
{
self::_versionCompare();
define('FOG_VERSION', '14');
define('FOG_VERSION', '19');
define('FOG_SCHEMA', 244);
define('FOG_BCACHE_VER', 111);
define('FOG_SVN_REVISION', 6052);
Expand Down
39 changes: 36 additions & 3 deletions packages/web/management/js/fog/fog.dashboard.js
Expand Up @@ -245,6 +245,17 @@ function UpdateBandwidthGraph(data) {
if (data === null || typeof(data) === 'undefined') {
data = '';
}
function retval(d) {
if (parseInt(d) < 1) {
return 0;
} else {
val = Math.round(d / 1024 * 8 / bandwidthtime, 2);
if (val < 1) {
val = 0;
}
return val;
}
}
var d = new Date();
var tx = new Array();
var rx = new Array();
Expand All @@ -259,16 +270,38 @@ function UpdateBandwidthGraph(data) {
GraphBandwidthData[i].dev = new Array();
GraphBandwidthData[i].tx = new Array();
GraphBandwidthData[i].rx = new Array();
GraphBandwidthData[i].txd = new Array();
GraphBandwidthData[i].rxd = new Array();
}
while (GraphBandwidthData[i].tx.length >= GraphBandwidthMaxDataPoints) {
GraphBandwidthData[i].tx.shift();
GraphBandwidthData[i].txd.shift();
}
while (GraphBandwidthData[i].rx.length >= GraphBandwidthMaxDataPoints) {
GraphBandwidthData[i].rx.shift();
GraphBandwidthData[i].rxd.shift();
}
if (data[i] === null) data[i] = {dev: 'Unknown',tx: 0,rx:0};
if (data[i].dev === 'Unknown' && GraphBandwidthData[i].dev !== 'Unknown') data[i].dev = GraphBandwidthData[i].dev;
tx_rate = Math.round(data[i].tx / bandwidthtime, 2);
if (data[i].dev === 'Unknown'
&& GraphBandwidthData[i].dev !== 'Unknown'
) {
data[i].dev = GraphBandwidthData[i].dev;
}
txlength = GraphBandwidthData[i].txd.length - 1;
rxlength = GraphBandwidthData[i].rxd.length - 1;
lasttx = GraphBandwidthData[i].txd[txlength];
lastrx = GraphBandwidthData[i].rxd[rxlength];
tx_rate = 0;
rx_rate = 0;
if (txlength > 0 && parseInt(lasttx) > 0) {
tx_rate = retval(data[i].tx - lasttx);
}
if (rxlength > 0 && parseInt(lastrx) > 0) {
rx_rate = retval(data[i].rx - lastrx);
}
GraphBandwidthData[i].txd.push(data[i].tx);
GraphBandwidthData[i].rxd.push(data[i].rx);
GraphBandwidthData[i].tx.push([Now,tx_rate]);
rx_rate = Math.round(data[i].rx / bandwidthtime, 2);
GraphBandwidthData[i].rx.push([Now,rx_rate]);
// Reset the old and new values for the next iteration.
GraphBandwidthData[i].dev = data[i].dev;
Expand Down
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: fog-project-2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-29 20:31-0500\n"
"POT-Creation-Date: 2016-12-30 19:13-0500\n"
"PO-Revision-Date: 2016-05-23 07:36-0400\n"
"Last-Translator: vspushbullet <vspushbullet@gmail.com>\n"
"Language-Team: German\n"
Expand Down Expand Up @@ -33,18 +33,18 @@ msgstr "Nicht in der Lage, die Datei zum Lesen öffnen"
msgid "IP Passed is incorrect"
msgstr "Es ist falsch, IP übergeben"

#: /var/www/fog/status/bandwidth.php:48
#: /var/www/fog/status/bandwidth.php:44
#, fuzzy
msgid "Device must be a string"
msgstr "Veranstaltung muss eine Zeichenfolge sein."

#: /var/www/fog/status/bandwidth.php:51
#: /var/www/fog/status/bandwidth.php:47
#: /var/www/fog/lib/fog/fogbase.class.php:1217
#, fuzzy
msgid "File must be a string"
msgstr "Veranstaltung muss eine Zeichenfolge sein."

#: /var/www/fog/status/bandwidth.php:54
#: /var/www/fog/status/bandwidth.php:50
msgid "Only tx and rx bytes files can be read"
msgstr ""

Expand Down
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-29 20:31-0500\n"
"POT-Creation-Date: 2016-12-30 19:13-0500\n"
"PO-Revision-Date: 2016-05-22 15:14-0400\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand All @@ -33,18 +33,18 @@ msgstr "Unable to open file for reading"
msgid "IP Passed is incorrect"
msgstr "IP Passed is incorrect"

#: /var/www/fog/status/bandwidth.php:48
#: /var/www/fog/status/bandwidth.php:44
#, fuzzy
msgid "Device must be a string"
msgstr "Event must be a string"

#: /var/www/fog/status/bandwidth.php:51
#: /var/www/fog/status/bandwidth.php:47
#: /var/www/fog/lib/fog/fogbase.class.php:1217
#, fuzzy
msgid "File must be a string"
msgstr "Event must be a string"

#: /var/www/fog/status/bandwidth.php:54
#: /var/www/fog/status/bandwidth.php:50
msgid "Only tx and rx bytes files can be read"
msgstr ""

Expand Down
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-29 20:31-0500\n"
"POT-Creation-Date: 2016-12-30 19:13-0500\n"
"PO-Revision-Date: 2016-05-22 15:14-0400\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand All @@ -34,18 +34,18 @@ msgstr "No se puede abrir archivo para lectura"
msgid "IP Passed is incorrect"
msgstr "Pasado IP es incorrecta"

#: /var/www/fog/status/bandwidth.php:48
#: /var/www/fog/status/bandwidth.php:44
#, fuzzy
msgid "Device must be a string"
msgstr "Evento debe ser una cadena"

#: /var/www/fog/status/bandwidth.php:51
#: /var/www/fog/status/bandwidth.php:47
#: /var/www/fog/lib/fog/fogbase.class.php:1217
#, fuzzy
msgid "File must be a string"
msgstr "Evento debe ser una cadena"

#: /var/www/fog/status/bandwidth.php:54
#: /var/www/fog/status/bandwidth.php:50
msgid "Only tx and rx bytes files can be read"
msgstr ""

Expand Down
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-29 20:31-0500\n"
"POT-Creation-Date: 2016-12-30 19:13-0500\n"
"PO-Revision-Date: 2016-05-22 15:14-0400\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand All @@ -34,18 +34,18 @@ msgstr "Impossible d'ouvrir le fichier pour la lecture"
msgid "IP Passed is incorrect"
msgstr "IP Passé est incorrect"

#: /var/www/fog/status/bandwidth.php:48
#: /var/www/fog/status/bandwidth.php:44
#, fuzzy
msgid "Device must be a string"
msgstr "Événement doit être une chaîne"

#: /var/www/fog/status/bandwidth.php:51
#: /var/www/fog/status/bandwidth.php:47
#: /var/www/fog/lib/fog/fogbase.class.php:1217
#, fuzzy
msgid "File must be a string"
msgstr "Événement doit être une chaîne"

#: /var/www/fog/status/bandwidth.php:54
#: /var/www/fog/status/bandwidth.php:50
msgid "Only tx and rx bytes files can be read"
msgstr ""

Expand Down
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-29 20:31-0500\n"
"POT-Creation-Date: 2016-12-30 19:13-0500\n"
"PO-Revision-Date: 2016-05-22 15:14-0400\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand All @@ -34,18 +34,18 @@ msgstr "Impossibile aprire il file per la lettura"
msgid "IP Passed is incorrect"
msgstr "IP Passato è corretto"

#: /var/www/fog/status/bandwidth.php:48
#: /var/www/fog/status/bandwidth.php:44
#, fuzzy
msgid "Device must be a string"
msgstr "Evento deve essere una stringa"

#: /var/www/fog/status/bandwidth.php:51
#: /var/www/fog/status/bandwidth.php:47
#: /var/www/fog/lib/fog/fogbase.class.php:1217
#, fuzzy
msgid "File must be a string"
msgstr "Evento deve essere una stringa"

#: /var/www/fog/status/bandwidth.php:54
#: /var/www/fog/status/bandwidth.php:50
msgid "Only tx and rx bytes files can be read"
msgstr ""

Expand Down
8 changes: 4 additions & 4 deletions packages/web/management/languages/messages.pot
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-30 13:00-0500\n"
"POT-Creation-Date: 2016-12-30 19:13-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -32,16 +32,16 @@ msgstr ""
msgid "IP Passed is incorrect"
msgstr ""

#: /var/www/fog/status/bandwidth.php:48
#: /var/www/fog/status/bandwidth.php:44
msgid "Device must be a string"
msgstr ""

#: /var/www/fog/status/bandwidth.php:51
#: /var/www/fog/status/bandwidth.php:47
#: /var/www/fog/lib/fog/fogbase.class.php:1217
msgid "File must be a string"
msgstr ""

#: /var/www/fog/status/bandwidth.php:54
#: /var/www/fog/status/bandwidth.php:50
msgid "Only tx and rx bytes files can be read"
msgstr ""

Expand Down
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-29 20:31-0500\n"
"POT-Creation-Date: 2016-12-30 19:13-0500\n"
"PO-Revision-Date: 2016-05-22 15:14-0400\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand All @@ -33,18 +33,18 @@ msgstr "Não é possível abrir arquivo para leitura"
msgid "IP Passed is incorrect"
msgstr "IP Passou está incorreta"

#: /var/www/fog/status/bandwidth.php:48
#: /var/www/fog/status/bandwidth.php:44
#, fuzzy
msgid "Device must be a string"
msgstr "Evento deve ser uma string"

#: /var/www/fog/status/bandwidth.php:51
#: /var/www/fog/status/bandwidth.php:47
#: /var/www/fog/lib/fog/fogbase.class.php:1217
#, fuzzy
msgid "File must be a string"
msgstr "Evento deve ser uma string"

#: /var/www/fog/status/bandwidth.php:54
#: /var/www/fog/status/bandwidth.php:50
msgid "Only tx and rx bytes files can be read"
msgstr ""

Expand Down
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-29 20:31-0500\n"
"POT-Creation-Date: 2016-12-30 19:13-0500\n"
"PO-Revision-Date: 2016-05-22 15:14-0400\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand All @@ -33,18 +33,18 @@ msgstr "无法打开文件进行读取"
msgid "IP Passed is incorrect"
msgstr "IP传递是不正确"

#: /var/www/fog/status/bandwidth.php:48
#: /var/www/fog/status/bandwidth.php:44
#, fuzzy
msgid "Device must be a string"
msgstr "事件必须是字符串"

#: /var/www/fog/status/bandwidth.php:51
#: /var/www/fog/status/bandwidth.php:47
#: /var/www/fog/lib/fog/fogbase.class.php:1217
#, fuzzy
msgid "File must be a string"
msgstr "事件必须是字符串"

#: /var/www/fog/status/bandwidth.php:54
#: /var/www/fog/status/bandwidth.php:50
msgid "Only tx and rx bytes files can be read"
msgstr ""

Expand Down
33 changes: 2 additions & 31 deletions packages/web/status/bandwidth.php
Expand Up @@ -27,10 +27,6 @@
ignore_user_abort(true);
set_time_limit(0);
header('Content-Type: text/event-stream');
$bandwidthtime = FOGCore::getClass('Service')
->set('name', 'FOG_BANDWIDTH_TIME')
->load('name')
->get('value');
/**
* Lambda for returning the bytes from the file requested.
*
Expand Down Expand Up @@ -61,23 +57,6 @@
return trim($data);
}
};
/**
* Lambda for returning the converted data for bytes from bits.
*
* If the data passed is not numeric or 0 or less, return 0
* otherwise formulate our data into Bps instead of bps.
*
* @param int|double $data the data to convert
*
* @return int|double
*/
$retval = function ($data) {
if (!(is_numeric($data) && $data > 0)) {
return 0;
} else {
return round(($data / 1024) * 8, 2);
}
};
// Make sure a device is set
if (!isset($_REQUEST['dev'])) {
$_REQUEST['dev'] = 'eth0';
Expand Down Expand Up @@ -132,16 +111,8 @@
exit;
}
// Set our rx and tx data values
$rx_data[] = $getBytes($dev, 'rx_bytes');
$tx_data[] = $getBytes($dev, 'tx_bytes');
sleep($bandwidthtime);
$rx_data[] = $getBytes($dev, 'rx_bytes');
$tx_data[] = $getBytes($dev, 'tx_bytes');
// Set our return data to converted.
$rx = $rx_data[1] - $rx_data[0];
$tx = $tx_data[1] - $tx_data[0];
$rx = $retval($rx);
$tx = $retval($tx);
$rx = $getBytes($dev, 'rx_bytes');
$tx = $getBytes($dev, 'tx_bytes');
// Setup our return array
$ret = array(
'dev' => $dev,
Expand Down

0 comments on commit be69d85

Please sign in to comment.