Report CPU/mem usage in GUI
This commit is contained in:
34
gui/app.js
34
gui/app.js
@@ -26,6 +26,9 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
||||
});
|
||||
|
||||
$scope.refresh = function () {
|
||||
$http.get("/rest/system").success(function (data) {
|
||||
$scope.system = data;
|
||||
});
|
||||
$http.get("/rest/model").success(function (data) {
|
||||
$scope.model = data;
|
||||
modelGetSucceeded();
|
||||
@@ -71,16 +74,19 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
||||
setInterval($scope.refresh, 10000);
|
||||
});
|
||||
|
||||
function decimals(num) {
|
||||
if (num > 100) {
|
||||
return 0;
|
||||
}
|
||||
if (num > 10) {
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
function decimals(val, num) {
|
||||
if (val === 0) { return 0; }
|
||||
var digits = Math.floor(Math.log(Math.abs(val))/Math.log(10));
|
||||
var decimals = Math.max(0, num - digits);
|
||||
return decimals;
|
||||
}
|
||||
|
||||
syncthing.filter('natural', function() {
|
||||
return function(input, valid) {
|
||||
return input.toFixed(decimals(input, valid));
|
||||
}
|
||||
});
|
||||
|
||||
syncthing.filter('binary', function() {
|
||||
return function(input) {
|
||||
if (input === undefined) {
|
||||
@@ -88,15 +94,15 @@ syncthing.filter('binary', function() {
|
||||
}
|
||||
if (input > 1024 * 1024 * 1024) {
|
||||
input /= 1024 * 1024 * 1024;
|
||||
return input.toFixed(decimals(input)) + ' Gi';
|
||||
return input.toFixed(decimals(input, 2)) + ' Gi';
|
||||
}
|
||||
if (input > 1024 * 1024) {
|
||||
input /= 1024 * 1024;
|
||||
return input.toFixed(decimals(input)) + ' Mi';
|
||||
return input.toFixed(decimals(input, 2)) + ' Mi';
|
||||
}
|
||||
if (input > 1024) {
|
||||
input /= 1024;
|
||||
return input.toFixed(decimals(input)) + ' Ki';
|
||||
return input.toFixed(decimals(input, 2)) + ' Ki';
|
||||
}
|
||||
return Math.round(input) + ' ';
|
||||
}
|
||||
@@ -109,15 +115,15 @@ syncthing.filter('metric', function() {
|
||||
}
|
||||
if (input > 1000 * 1000 * 1000) {
|
||||
input /= 1000 * 1000 * 1000;
|
||||
return input.toFixed(decimals(input)) + ' G';
|
||||
return input.toFixed(decimals(input, 2)) + ' G';
|
||||
}
|
||||
if (input > 1000 * 1000) {
|
||||
input /= 1000 * 1000;
|
||||
return input.toFixed(decimals(input)) + ' M';
|
||||
return input.toFixed(decimals(input, 2)) + ' M';
|
||||
}
|
||||
if (input > 1000) {
|
||||
input /= 1000;
|
||||
return input.toFixed(decimals(input)) + ' k';
|
||||
return input.toFixed(decimals(input, 2)) + ' k';
|
||||
}
|
||||
return Math.round(input) + ' ';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user