diff --git a/js/app.js b/js/app.js
index 487e67da..30790b97 100644
--- a/js/app.js
+++ b/js/app.js
@@ -7,6 +7,14 @@ app = Sammy('#main', function (sam) {
// Plugins
sam.use('Handlebars', 'ms');
+ Handlebars.registerHelper('humanSize', function(bytes) {
+ var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
+ if (bytes == 0) return 'n/a';
+ var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
+ return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[[i]];
+ });
+
+
// Look for supported type of storage to use
var storageType;
if (Sammy.Store.isAvailable('session')) {
@@ -577,56 +585,21 @@ app = Sammy('#main', function (sam) {
sam.get('#/monitor', function (c) {
monitorData = {}
- // Put this function elswere ?
- function bytesToSize(bytes) {
- var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
- if (bytes == 0) return 'n/a';
- var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
- return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[[i]];
- };
-
// Why this method ?
c.api('/monitor/update-stats', function(data) { // ?
c.api('/monitor/system', function(data) {
monitorData.system = data;
- // Convert byte to human readable string
- $.each(monitorData.system.memory, function(k,v) {
- monitorData.system.memory[k].free = bytesToSize(v.free);
- monitorData.system.memory[k].used = bytesToSize(v.used);
- monitorData.system.memory[k].total = bytesToSize(v.total);
- });
-
c.api('/monitor/disk', function(data) {
monitorData.disk = data;
- // Convert byte to human readable string
- $.each(monitorData.disk, function(k,v) {
- monitorData.disk[k].filesystem.avail = bytesToSize(v.filesystem.avail);
- monitorData.disk[k].filesystem.size = bytesToSize(v.filesystem.size);
- monitorData.disk[k].filesystem.used = bytesToSize(v.filesystem.used);
- monitorData.disk[k].io.read_bytes = bytesToSize(v.io.read_bytes);
- monitorData.disk[k].io.write_bytes = bytesToSize(v.io.write_bytes);
- });
-
c.api('/monitor/network', function(data) {
monitorData.network = data;
// Remove useless interface
delete monitorData.network.usage.lo;
- // Convert byte to human readable string
- $.each(monitorData.network.usage, function(k,v) {
- monitorData.network.usage[k].cx = bytesToSize(v.cx);
- monitorData.network.usage[k].cumulative_cx = bytesToSize(v.cumulative_cx);
- monitorData.network.usage[k].rx = bytesToSize(v.rx);
- monitorData.network.usage[k].cumulative_rx = bytesToSize(v.cumulative_rx);
- monitorData.network.usage[k].tx = bytesToSize(v.tx);
- monitorData.network.usage[k].cumulative_tx = bytesToSize(v.cumulative_tx);
- });
-
-
c.view('monitor', monitorData);
});
diff --git a/views/monitor.ms b/views/monitor.ms
index 6d37fb22..b7a75d64 100644
--- a/views/monitor.ms
+++ b/views/monitor.ms
@@ -36,15 +36,15 @@
Used |
- {{system.memory.ram.used}} ({{system.memory.ram.percent}} %) |
+ {{humanSize system.memory.ram.used}} ({{system.memory.ram.percent}} %) |
Free |
- {{system.memory.ram.free}} |
+ {{humanSize system.memory.ram.free}} |
Total |
- {{system.memory.ram.total}} |
+ {{humanSize system.memory.ram.total}} |
@@ -52,15 +52,15 @@
Used |
- {{system.memory.swap.used}} ({{system.memory.swap.percent}} %) |
+ {{humanSize system.memory.swap.used}} ({{system.memory.swap.percent}} %) |
Free |
- {{system.memory.swap.free}} |
+ {{humanSize system.memory.swap.free}} |
Total |
- {{system.memory.swap.total}} |
+ {{humanSize system.memory.swap.total}} |
@@ -147,18 +147,18 @@
Cx |
- {{cx}} |
- {{cumulative_cx}} (cumulative) |
+ {{humanSize cx}} |
+ {{humanSize cumulative_cx}} (cumulative) |
Rx |
- {{rx}} |
- {{cumulative_rx}} (cumulative) |
+ {{humanSize rx}} |
+ {{humanSize cumulative_rx}} (cumulative) |
Tx |
- {{tx}} |
- {{cumulative_tx}} (cumulative) |
+ {{humanSize tx}} |
+ {{humanSize cumulative_tx}} (cumulative) |
{{/each}}
@@ -188,13 +188,13 @@
Mount point | {{ filesystem.mnt_point }} |
- Size | {{ filesystem.size }} |
+ Size | {{humanSize filesystem.size }} |
- Used | {{ filesystem.used }} |
+ Used | {{humanSize filesystem.used }} |
- Available | {{ filesystem.avail }} |
+ Available | {{humanSize filesystem.avail }} |
@@ -202,10 +202,10 @@
I/O Time since update: {{ io.time_since_update }}
- Read | {{ io.read_bytes }} |
+ Read | {{humanSize io.read_bytes }} |
- Write | {{ io.write_bytes }} |
+ Write | {{humanSize io.write_bytes }} |