index.js 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. */
  15. solrAdminApp.controller('IndexController', function($scope, System, Cores, Constants) {
  16. $scope.resetMenu("index", Constants.IS_ROOT_PAGE);
  17. $scope.reload = function() {
  18. System.get(function(data) {
  19. $scope.system = data;
  20. // load average
  21. var load_average = ( data.system.uptime || '' ).match( /load averages?: (\d+[.,]\d\d),? (\d+[.,]\d\d),? (\d+[.,]\d\d)/ );
  22. if (load_average) {
  23. for (var i=0;i<2;i++) {
  24. load_average[i]=load_average[i].replace(",","."); // for European users
  25. }
  26. $scope.load_average = load_average.slice(1);
  27. }
  28. // physical memory
  29. var memoryMax = parse_memory_value(data.system.totalPhysicalMemorySize);
  30. $scope.memoryTotal = parse_memory_value(data.system.totalPhysicalMemorySize - data.system.freePhysicalMemorySize);
  31. $scope.memoryPercentage = ($scope.memoryTotal / memoryMax * 100).toFixed(1)+ "%";
  32. $scope.memoryMax = pretty_print_bytes(memoryMax);
  33. $scope.memoryTotalDisplay = pretty_print_bytes($scope.memoryTotal);
  34. // swap space
  35. var swapMax = parse_memory_value(data.system.totalSwapSpaceSize);
  36. $scope.swapTotal = parse_memory_value(data.system.totalSwapSpaceSize - data.system.freeSwapSpaceSize);
  37. $scope.swapPercentage = ($scope.swapTotal / swapMax * 100).toFixed(1)+ "%";
  38. $scope.swapMax = pretty_print_bytes(swapMax);
  39. $scope.swapTotalDisplay = pretty_print_bytes($scope.swapTotal);
  40. // file handles
  41. $scope.fileDescriptorPercentage = (data.system.openFileDescriptorCount / data.system.maxFileDescriptorCount *100).toFixed(1) + "%";
  42. // java memory
  43. var javaMemoryMax = parse_memory_value(data.jvm.memory.raw.max || data.jvm.memory.max);
  44. $scope.javaMemoryTotal = parse_memory_value(data.jvm.memory.raw.total || data.jvm.memory.total);
  45. $scope.javaMemoryUsed = parse_memory_value(data.jvm.memory.raw.used || data.jvm.memory.used);
  46. $scope.javaMemoryTotalPercentage = ($scope.javaMemoryTotal / javaMemoryMax *100).toFixed(1) + "%";
  47. $scope.javaMemoryUsedPercentage = ($scope.javaMemoryUsed / $scope.javaMemoryTotal *100).toFixed(1) + "%";
  48. $scope.javaMemoryPercentage = ($scope.javaMemoryUsed / javaMemoryMax * 100).toFixed(1) + "%";
  49. $scope.javaMemoryTotalDisplay = pretty_print_bytes($scope.javaMemoryTotal);
  50. $scope.javaMemoryUsedDisplay = pretty_print_bytes($scope.javaMemoryUsed); // @todo These should really be an AngularJS Filter: {{ javaMemoryUsed | bytes }}
  51. $scope.javaMemoryMax = pretty_print_bytes(javaMemoryMax);
  52. // no info bar:
  53. $scope.noInfo = !(
  54. data.system.totalPhysicalMemorySize && data.system.freePhysicalMemorySize &&
  55. data.system.totalSwapSpaceSize && data.system.freeSwapSpaceSize &&
  56. data.system.openFileDescriptorCount && data.system.maxFileDescriptorCount);
  57. // command line args:
  58. $scope.commandLineArgs = data.jvm.jmx.commandLineArgs.sort();
  59. });
  60. };
  61. $scope.reload();
  62. });
  63. var parse_memory_value = function( value ) {
  64. if( value !== Number( value ) )
  65. {
  66. var units = 'BKMGTPEZY';
  67. var match = value.match( /^(\d+([,\.]\d+)?) (\w).*$/ );
  68. var value = parseFloat( match[1] ) * Math.pow( 1024, units.indexOf( match[3].toUpperCase() ) );
  69. }
  70. return value;
  71. };
  72. var pretty_print_bytes = function(byte_value) {
  73. var unit = null;
  74. byte_value /= 1024;
  75. byte_value /= 1024;
  76. unit = 'MB';
  77. if( 1024 <= byte_value ) {
  78. byte_value /= 1024;
  79. unit = 'GB';
  80. }
  81. return byte_value.toFixed( 2 ) + ' ' + unit;
  82. };