From 90a32fa60ce3e58a30ec46e624da0597571a0347 Mon Sep 17 00:00:00 2001 From: Stephan Schwaer Date: Thu, 28 May 2015 18:31:27 +0200 Subject: Added upload rate to the server statistics. --- static/status-dnbd3.html | 70 +++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 24 deletions(-) (limited to 'static') 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("
"); - 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 = " Server: " + stats[i].address + "
"
+ server.html( "
Server: " + stats[i].address + "
"
+ "Number of clients: "
+ stats[i].clientCount + "
"
+ "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" + "
"
- + "Sent: " + sent + unitSent + "
"
- + "Received: " + received + unitReceived + "