heatmap.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. App.MainChartsHeatmapController = Em.Controller.extend({
  19. name: 'mainChartsHeatmapController',
  20. modelRacks: App.Rack.find(),
  21. racks: function () {
  22. var racks = [];
  23. this.get('modelRacks').forEach(function (rack) {
  24. racks.push(Em.Object.create({
  25. name: rack.get('name'),
  26. hosts: rack.get('hosts'),
  27. isLoaded: false
  28. }));
  29. });
  30. return racks;
  31. }.property('modelRacks.@each.isLoaded'),
  32. allMetrics: function () {
  33. var metrics = [];
  34. // Display host heatmaps if the stack definition has a host metrics service to display it.
  35. if(App.get('services.hostMetrics').length) {
  36. metrics.push(
  37. Em.Object.create({
  38. label: Em.I18n.t('charts.heatmap.category.host'),
  39. category: 'host',
  40. items: [
  41. App.MainChartHeatmapDiskSpaceUsedMetric.create(),
  42. App.MainChartHeatmapMemoryUsedMetric.create(),
  43. App.MainChartHeatmapCpuWaitIOMetric.create()
  44. /*, App.MainChartHeatmapProcessRunMetric.create()*/
  45. ]
  46. })
  47. );
  48. }
  49. if(App.HDFSService.find().get('length')) {
  50. metrics.push(
  51. Em.Object.create({
  52. label: Em.I18n.t('charts.heatmap.category.hdfs'),
  53. category: 'hdfs',
  54. items: [
  55. App.MainChartHeatmapDFSBytesReadMetric.create(),
  56. App.MainChartHeatmapDFSBytesWrittenMetric.create(),
  57. App.MainChartHeatmapDFSGCTimeMillisMetric.create(),
  58. App.MainChartHeatmapDFSMemHeapUsedMetric.create()
  59. ]
  60. })
  61. );
  62. }
  63. if (App.MapReduceService.find().get('length')) {
  64. metrics.push(
  65. Em.Object.create({
  66. label: Em.I18n.t('charts.heatmap.category.mapreduce'),
  67. category: 'mapreduce',
  68. items: [
  69. App.MainChartHeatmapMapreduceMapsRunningMetric.create(),
  70. App.MainChartHeatmapMapreduceReducesRunningMetric.create(),
  71. App.MainChartHeatmapMapreduceGCTimeMillisMetric.create(),
  72. App.MainChartHeatmapMapreduceMemHeapUsedMetric.create()
  73. ]
  74. })
  75. );
  76. }
  77. if (App.YARNService.find().get('length')) {
  78. metrics.push(
  79. Em.Object.create({
  80. label: Em.I18n.t('charts.heatmap.category.yarn'),
  81. category: 'yarn',
  82. items: [
  83. App.MainChartHeatmapYarnGCTimeMillisMetric.create(),
  84. App.MainChartHeatmapYarnMemHeapUsedMetric.create(),
  85. App.MainChartHeatmapYarnResourceUsedMetric.create()
  86. ]
  87. })
  88. );
  89. }
  90. if (App.HBaseService.find().get('length')) {
  91. metrics.push(
  92. Em.Object.create({
  93. label: Em.I18n.t('charts.heatmap.category.hbase'),
  94. category: 'hbase',
  95. items: [
  96. App.MainChartHeatmapHbaseReadReqCount.create(),
  97. App.MainChartHeatmapHbaseWriteReqCount.create(),
  98. App.MainChartHeatmapHbaseCompactionQueueSize.create(),
  99. App.MainChartHeatmapHbaseRegions.create(),
  100. App.MainChartHeatmapHbaseMemStoreSize.create()
  101. ]
  102. })
  103. );
  104. }
  105. return metrics;
  106. }.property(),
  107. selectedMetric: null,
  108. inputMaximum: '',
  109. validation: function () {
  110. if (this.get('selectedMetric')) {
  111. if (/^\d+$/.test(this.get('inputMaximum'))) {
  112. $('#inputMaximum').removeClass('error');
  113. this.set('selectedMetric.maximumValue', this.get('inputMaximum'));
  114. } else {
  115. $('#inputMaximum').addClass('error');
  116. }
  117. }
  118. }.observes('inputMaximum'),
  119. showHeatMapMetric: function (event) {
  120. var metricItem = event.context;
  121. if (metricItem) {
  122. this.set('selectedMetric', metricItem);
  123. }
  124. },
  125. hostToSlotMap: function () {
  126. return this.get('selectedMetric.hostToSlotMap');
  127. }.property('selectedMetric.hostToSlotMap'),
  128. loadMetrics: function () {
  129. var selectedMetric = this.get('selectedMetric');
  130. var hostNames = [];
  131. if (selectedMetric && this.get('racks').everyProperty('isLoaded', true)) {
  132. this.get('racks').forEach(function (rack) {
  133. hostNames = hostNames.concat(rack.hosts.mapProperty('hostName'));
  134. });
  135. selectedMetric.refreshHostSlots(hostNames);
  136. }
  137. this.set('inputMaximum', this.get('selectedMetric.maximumValue'));
  138. }.observes('selectedMetric'),
  139. /**
  140. * return class name for to be used for containing each rack.
  141. *
  142. * @this App.MainChartsHeatmapController
  143. */
  144. rackClass: function () {
  145. var rackCount = this.get('racks.length');
  146. if (rackCount < 2) {
  147. return "span12";
  148. } else if (rackCount == 2) {
  149. return "span6";
  150. } else {
  151. return "span4";
  152. }
  153. }.property('racks.length')
  154. });