status.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. angular.module("robware").controller('status', ["$scope", "statusService", "$interval", function($scope, statusService, $interval) {
  2. $scope.chartData=[];
  3. var chartDataId=0;
  4. function reloadUptime() {
  5. statusService.getUptime().then(function(data) {
  6. $scope.uptime = data;
  7. $scope.haveUptime = true;
  8. });
  9. }
  10. $scope.haveUptime = false;
  11. $scope.uptime = {};
  12. reloadUptime();
  13. $interval(reloadUptime, 60000);
  14. function reloadSystemInfo() {
  15. statusService.getSystemInfo().then(function(data) {
  16. if ($scope.chartData.length>=50)
  17. $scope.chartData.shift();
  18. $scope.chartData=$scope.chartData.concat([{id: chartDataId, CPU: data.load[0]*100, Mem: data.memUsage, Temp: data.cpuTemp}]);
  19. chartDataId++;
  20. $scope.load = data.load;
  21. $scope.cpuTemp = data.cpuTemp;
  22. $scope.memory = {
  23. free: data.memFree,
  24. used: data.memUsage,
  25. total: data.memTotal
  26. };
  27. $scope.haveSystemInfo = true;
  28. });
  29. }
  30. $scope.haveSystemInfo = false;
  31. $scope.load = {};
  32. $scope.loadHistory = [];
  33. $scope.cpuTemp = 0;
  34. $scope.systemInfoRefreshInterval = 5;
  35. var systemRefresh = $interval(reloadSystemInfo, $scope.systemInfoRefreshInterval * 1000);
  36. reloadSystemInfo();
  37. $scope.changeSystemInfoRefreshInterval = function(amount) {
  38. $scope.systemInfoRefreshInterval += amount;
  39. if ($scope.systemInfoRefreshInterval < 1)
  40. return;
  41. $interval.cancel(systemRefresh);
  42. systemRefresh = $interval(reloadSystemInfo, $scope.systemInfoRefreshInterval * 1000);
  43. };
  44. function reloadProcesses() {
  45. statusService.getProcesses().then(function(data) {
  46. $scope.processes = data;
  47. $scope.haveProcesses = true;
  48. });
  49. }
  50. $scope.haveProcesses = false;
  51. $scope.processses = {};
  52. $scope.processRefreshInterval = 10;
  53. var processRefesh = $interval(reloadProcesses, $scope.processRefreshInterval * 1000);
  54. reloadProcesses();
  55. $scope.changeProcesRefreshInterval = function(amount) {
  56. $scope.processRefreshInterval += amount;
  57. if ($scope.processRefreshInterval < 1)
  58. return;
  59. $interval.cancel(processRefesh);
  60. processRefesh = $interval(reloadProcesses, $scope.processRefreshInterval * 1000);
  61. };
  62. }]);