summaryrefslogtreecommitdiffstats
path: root/static
diff options
context:
space:
mode:
authorStephan Schwaer2015-05-28 18:31:27 +0200
committerStephan Schwaer2015-05-28 18:31:27 +0200
commit90a32fa60ce3e58a30ec46e624da0597571a0347 (patch)
tree13d997bdbf7c75e30490e2473ece349dd96cda92 /static
parentFixed graphn scaling (diff)
downloaddnbd3-status-90a32fa60ce3e58a30ec46e624da0597571a0347.tar.gz
dnbd3-status-90a32fa60ce3e58a30ec46e624da0597571a0347.tar.xz
dnbd3-status-90a32fa60ce3e58a30ec46e624da0597571a0347.zip
Added upload rate to the server statistics.
Diffstat (limited to 'static')
-rw-r--r--static/status-dnbd3.html70
1 files changed, 46 insertions, 24 deletions
diff --git a/static/status-dnbd3.html b/static/status-dnbd3.html
index 1ac6155..645447f 100644
--- a/static/status-dnbd3.html
+++ b/static/status-dnbd3.html
@@ -29,7 +29,7 @@ var colorList = d3.scale.category20();
// IDs need to begin with a letter.
function makeId(prefix, text) {
- return prefix + text.replace(/\./g, "-");
+ return prefix + text.replace(/\./g, "-");
}
function myGraph(el) {
@@ -305,6 +305,7 @@ setInterval( function() {
var g = data.graph;
var stats = data.servers;
updateGraph(g, data);
+ // updateTrafficGraph has to be called before updateTextStatistics to populate servers
updateTrafficGraph(stats, data);
updateTextStatistics(stats);
lastTime = data.timestamp;
@@ -326,37 +327,53 @@ function updateGraph(g, data){
}
}
+
+// Convert bytes to GiB or TiB and return a string in form "10,23 GiB"
+function bytesToString( bytes ) {
+ var convertedValue;
+ var unit;
+ if (bytes > 1099511627776 ) {
+ convertedValue = Math.round( (bytes / 1099511627776) * 100 ) / 100 ;
+ unit = " TiB";
+ } else if (bytes > 1073741824 ) {
+ convertedValue = Math.round( (bytes / 1073741824) * 100 ) / 100 ;
+ unit = " GiB";
+ } else if (bytes > 1048576 ) {
+ convertedValue = Math.round( (bytes / 1048576) * 100 ) / 100 ;
+ unit = " MiB";
+ } else if ( bytes > 1024 ) {
+ convertedValue = Math.round( (bytes / 1024) * 100 ) / 100 ;
+// convertedValue = Math.round( ( convertedValue / 1024 ) * 100 ) / 100;
+ unit = " KiB";
+ } else {
+ convertedValue = Math.round(bytes);
+ unit = " B";
+ }
+ return convertedValue + unit;
+}
+
// Update data of the statistics divs
function updateTextStatistics(stats){
if (stats) {
for (var i = 0; i < stats.length; ++i) {
- var server = document.getElementById(makeId("b", stats[i].address));
- if (!server){
+ var divId = makeId("b", stats[i].address);
+ var server = $('#' + divId);
+ if (server.length == 0){
$("#statistics").append("<div id=" + makeId ("b", stats[i].address) + "></div>");
- server = document.getElementById(makeId("b", stats[i].address));
-
- }
- var sent = Math.floor(stats[i].bytesSent / Math.pow(1024, 3));
- var received = Math.floor(stats[i].bytesReceived / Math.pow(1024, 3));
- var unitSent = " GiB";
- var unitReceived = " GiB";
- if (sent > 1024) {
- sent = Math.round((sent/1024)*100)/100;
- unitSent = " TiB";
- }
- if (received > 1024) {
- received = Math.round((received/1024)*100)/100;
- unitReceived = " TiB";
+ server = $("#" + divId);
}
+ var upload = servers[stats[i].address].uploadRate;
+ upload = upload ? upload : 0;
// Generate the HTML string
- server.innerHTML = "<p><b> Server: " + stats[i].address + "</b><br>"
+ server.html( "<p><b> Server: " + stats[i].address + "</b><br>"
+ "Number of clients: "
+ stats[i].clientCount + "<br>"
+ "uptime: " + Math.floor(stats[i].uptime / (3600 * 24)) + "d "
+ Math.floor(stats[i].uptime / 3600) % 24 + "h " + Math.floor((stats[i].uptime) / 60) % 60 + "min" + "<br>"
- + "Sent: " + sent + unitSent + " <br>"
- + "Received: " + received + unitReceived + " </p>";
+ + "Sent: " + bytesToString(stats[i].bytesSent) + "<br>"
+ + "Received: " + bytesToString(stats[i].bytesReceived) + "<br>"
+ + "Upload: " + bytesToString(servers[stats[i].address].uploadRate) + "/s" + "</p>");
}
}
}
@@ -368,19 +385,24 @@ function updateTrafficGraph(stats, data){
for (var i = 0; i < stats.length; ++i) {
var server = servers[stats[i].address];
if (!server) {
- servers[stats[i].address] = server = { 'lastUptime': 0, 'lastSent': 0, 'line': new TimeSeries(), 'index': serverCount++ };
+ servers[stats[i].address] = server = { 'lastUptime': 0, 'lastSent': 0, 'line': new TimeSeries(), 'index': serverCount++ , 'uploadRate': 0, 'downloadRate': 0}
server.color = colorList(stats[i].address);
smoothie.addTimeSeries(server['line'], {lineWidth:2, strokeStyle: server.color});
-// console.log("Added");
+// console.log("Added");
}
// Server seems to have rebootet, redo values but add no point to chart.
if (server['lastUptime'] > stats[i].uptime) {
server['lastUptime'] = 0;
}
- // Add points to graph
+ // Add points to graph and set the upload rate for the statistics
if (server['lastUptime'] != 0) {
- server['line'].append(new Date().getTime(), (stats[i].bytesSent - server['lastSent'])/1000/(data.timestamp - lastTime));
+ // Upload rate in bytes/s
+ server['uploadRate'] = (stats[i].bytesSent - server['lastSent'])/(data.timestamp - lastTime) * 1000;
+ // Rate in MiB/s
+ server['line'].append(new Date().getTime(), server['uploadRate']/( 1024 * 1024));
+ } else {
+ server['uploadRate'] = 0;
}
server['lastUptime'] = stats[i].uptime;