namenode_heap.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.NameNodeHeapPieChartView = App.DashboardWidgetView.extend({
  20. templateName: require('templates/main/dashboard/widgets/pie_chart'),
  21. title: Em.I18n.t('dashboard.widgets.NameNodeHeap'),
  22. id: '1',
  23. isPieChart: true,
  24. isText: false,
  25. isProgressBar: false,
  26. model_type: 'hdfs',
  27. hiddenInfo: function () {
  28. var memUsed = this.get('model').get('jvmMemoryHeapUsed') * 1000000;
  29. var memCommitted = this.get('model').get('jvmMemoryHeapCommitted') * 1000000;
  30. var percent = memCommitted > 0 ? ((100 * memUsed) / memCommitted) : 0;
  31. var result = [];
  32. result.pushObject(percent.toFixed(1) + '% used');
  33. result.pushObject(memUsed.bytesToSize(1, 'parseFloat') + ' of ' + memCommitted.bytesToSize(1, 'parseFloat'));
  34. return result;
  35. }.property('model.jvmMemoryHeapUsed', 'model.jvmMemoryHeapCommitted'),
  36. thresh1: null,
  37. thresh2: null,
  38. maxValue: 100,
  39. isPieExist: function () {
  40. var total = this.get('model.jvmMemoryHeapCommitted') * 1000000;
  41. return total > 0 ;
  42. }.property('model.jvmMemoryHeapCommitted'),
  43. content: App.ChartPieView.extend({
  44. model: null, //data bind here
  45. id: 'widget-nn-heap', // html id
  46. stroke: '#D6DDDF', //light grey
  47. thresh1: null, //bind from parent
  48. thresh2: null,
  49. innerR: 25,
  50. existCenterText: true,
  51. centerTextColor: function () {
  52. return this.get('contentColor');
  53. }.property('contentColor'),
  54. palette: new Rickshaw.Color.Palette({
  55. scheme: [ '#FFFFFF', '#D6DDDF'].reverse()
  56. }),
  57. data: function () {
  58. var used = this.get('model.jvmMemoryHeapUsed') * 1000000;
  59. var total = this.get('model.jvmMemoryHeapCommitted') * 1000000;
  60. var percent = total > 0 ? ((used)*100 / total).toFixed() : 0;
  61. return [ percent, 100 - percent];
  62. }.property('model.jvmMemoryHeapUsed', 'model.jvmMemoryHeapCommitted'),
  63. contentColor: function () {
  64. var used = parseFloat(this.get('data')[0]);
  65. var thresh1 = parseFloat(this.get('thresh1'));
  66. var thresh2 = parseFloat(this.get('thresh2'));
  67. var color_green = '#95A800';
  68. var color_red = '#B80000';
  69. var color_orange = '#FF8E00';
  70. if (used <= thresh1) {
  71. this.set('palette', new Rickshaw.Color.Palette({
  72. scheme: [ '#FFFFFF', color_green ].reverse()
  73. }))
  74. return color_green;
  75. } else if (used <= thresh2) {
  76. this.set('palette', new Rickshaw.Color.Palette({
  77. scheme: [ '#FFFFFF', color_orange ].reverse()
  78. }))
  79. return color_orange;
  80. } else {
  81. this.set('palette', new Rickshaw.Color.Palette({
  82. scheme: [ '#FFFFFF', color_red ].reverse()
  83. }))
  84. return color_red;
  85. }
  86. }.property('data', 'this.thresh1', 'this.thresh2'),
  87. // refresh text and color when data in model changed
  88. refreshSvg: function () {
  89. // remove old svg
  90. var old_svg = $("#" + this.id);
  91. if(old_svg){
  92. old_svg.remove();
  93. }
  94. // draw new svg
  95. this.appendSvg();
  96. }.observes('model.jvmMemoryHeapUsed', 'model.jvmMemoryHeapCommitted', 'this.thresh1', 'this.thresh2')
  97. })
  98. })