diff --git a/js/app.js b/js/app.js index 687f5118..487e67da 100644 --- a/js/app.js +++ b/js/app.js @@ -231,6 +231,7 @@ app = Sammy('#main', function (sam) { * */ sam.get('#/', function (c) { + // Show development note c.flash('info', 'You are using a development version.
' + 'Please note that you can use the moulinette if you want to access to more YunoHost\'s features.'); @@ -241,6 +242,7 @@ app = Sammy('#main', function (sam) { {name: "Domains", path: '#/domains'}, {name: "Applications", path: '#/apps'}, {name: "Services", path: '#/services'}, + {name: "Monitoring", path: '#/monitor'}, ]}; c.view('home', data); @@ -566,6 +568,77 @@ app = Sammy('#main', function (sam) { }); + /** + * Monitor + * + */ + + // + 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); + }); + + }); + }); + + + }, 'POST', {period: 'day'}); + }); + + + }); diff --git a/views/monitor.ms b/views/monitor.ms new file mode 100644 index 00000000..6d37fb22 --- /dev/null +++ b/views/monitor.ms @@ -0,0 +1,220 @@ +
+ Menu +
+
+
Monitoring
+
+ +
+
+

Infos

+
+
+ +
+
+ +
+ +
+
+

+ + System +

+
+
+
+ +
+

Memory

+

RAM

+ + + + + + + + + + + + + +
Used{{system.memory.ram.used}} ({{system.memory.ram.percent}} %)
Free{{system.memory.ram.free}}
Total{{system.memory.ram.total}}
+ +

Swap

+ + + + + + + + + + + + + +
Used{{system.memory.swap.used}} ({{system.memory.swap.percent}} %)
Free{{system.memory.swap.free}}
Total{{system.memory.swap.total}}
+
+ +
+

CPU Load

+ + + + + + + + + + + + + +
1 min{{system.cpu.load.min1}}
5 min{{system.cpu.load.min5}}
15 min{{system.cpu.load.min15}}
+
+ +
+

Process

+ + + + + + + + + + + + + +
Running{{system.process.running}}
Sleeping{{system.process.sleeping}}
Total{{system.process.total}}
+
+
+
+
+ +
+
+

+ + Network +

+
+
+
+ Public IP: {{network.infos.public_ip}} +
+ Gateway: {{network.infos.gateway}} + +

Local IP

+ + + + + + + + + + {{#each network.infos.local_ip}} + + + {{#this}} + + {{/this}} + + {{/each}} + +
InterfaceIPv4IPv6
{{@key}}{{.}}
+ +

Usage

+ {{#each network.usage}} +

+ {{@key}} + Time since update: {{time_since_update}} +

+ + + + + + + + + + + + + + + + +
Cx{{cx}}{{cumulative_cx}} (cumulative)
Rx{{rx}}{{cumulative_rx}} (cumulative)
Tx{{tx}}{{cumulative_tx}} (cumulative)
+ {{/each}} +
+
+
+ +
+
+

+ + Disk +

+
+
+
+ {{#each disk}} +

{{@key}}

+
+
+

Filesystem

+ + + + + + + + + + + + + + + + +
FS Type{{ filesystem.fs_type }}
Mount point{{ filesystem.mnt_point }}
Size{{ filesystem.size }}
Used{{ filesystem.used }}
Available{{ filesystem.avail }}
+
+
+

I/O Time since update: {{ io.time_since_update }}

+ + + + + + + +
Read{{ io.read_bytes }}
Write{{ io.write_bytes }}
+
+ {{/each}} +
+
+
+ +
+ + +
\ No newline at end of file