heatmap_host.js 4.9 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 date = require('utils/date/date');
  18. var App = require('app');
  19. App.MainChartsHeatmapHostView = Em.View.extend({
  20. templateName: require('templates/main/charts/heatmap/heatmap_host'),
  21. didInsertElement: function() {
  22. $("#heatmapDetailsBlock").hide();
  23. },
  24. /** @private */
  25. hostClass: 'hostBlock',
  26. /**
  27. * link to host record in App.Host model
  28. */
  29. hostModelLink: function () {
  30. return App.Host.find(this.get('content.hostName'));
  31. }.property('content.hostName'),
  32. /**
  33. * show Host details block and move it near the cursor
  34. *
  35. * @param {Object} event
  36. * @this App.MainChartsHeatmapHostView
  37. */
  38. mouseEnter: function (event) {
  39. var host = this.get('content');
  40. var view = App.MainChartsHeatmapHostDetailView.create();
  41. var self = this;
  42. var nonClientComponents = App.get('components.slaves').concat(App.get('components.masters'));
  43. $.each(view.get('details'), function (i) {
  44. var val = host[i];
  45. switch (i) {
  46. case 'diskUsage':
  47. val = self.getUsage(host, 'diskTotal', 'diskFree');
  48. break;
  49. case 'cpuUsage':
  50. val = 0;
  51. if (Number.isFinite(host.cpuSystem) && Number.isFinite(host.cpuUser)) {
  52. val = host.cpuSystem + host.cpuUser;
  53. }
  54. val = val.toFixed(1);
  55. break;
  56. case 'memoryUsage':
  57. val = self.getUsage(host, 'memTotal', 'memFree');
  58. break;
  59. case 'hostComponents':
  60. val = [];
  61. host[i].forEach(function (componentName) {
  62. if (nonClientComponents.contains(componentName)) {
  63. val.push(App.format.role(componentName));
  64. }
  65. }, this);
  66. val = val.join(', ')
  67. }
  68. view.set('details.' + i, val);
  69. });
  70. this.setMetric(view, host);
  71. this.openDetailsBlock(event);
  72. },
  73. /**
  74. * show tooltip with host's details
  75. */
  76. openDetailsBlock: function (event) {
  77. var detailsBlock = $("#heatmapDetailsBlock");
  78. detailsBlock.css('top', event.pageY + 10);
  79. detailsBlock.css('left', event.pageX + 10);
  80. detailsBlock.show();
  81. },
  82. /**
  83. * set name and value of selected metric
  84. * @param view
  85. * @param host
  86. */
  87. setMetric: function (view, host) {
  88. var selectedMetric = this.get('controller.selectedMetric');
  89. if (selectedMetric) {
  90. var metricName = selectedMetric.get('name');
  91. var h2vMap = selectedMetric.get('hostToValueMap');
  92. if (h2vMap && metricName) {
  93. var value = h2vMap[host.hostName];
  94. if (Em.isNone(value)) {
  95. value = this.t('charts.heatmap.unknown');
  96. } else {
  97. if (metricName == 'Garbage Collection Time') {
  98. value = date.timingFormat(parseInt(value));
  99. } else {
  100. if (isNaN(value)) {
  101. value = this.t('charts.heatmap.unknown');
  102. } else {
  103. value = value + selectedMetric.get('units');
  104. }
  105. }
  106. }
  107. view.set('details.metricName', metricName);
  108. view.set('details.metricValue', value);
  109. }
  110. }
  111. },
  112. /**
  113. * get relative usage of metric in percents
  114. * @param item
  115. * @param totalProperty
  116. * @param freeProperty
  117. * @return {String}
  118. */
  119. getUsage: function (item, totalProperty, freeProperty) {
  120. var result = 0;
  121. var total = item[totalProperty];
  122. if (Number.isFinite(total) && Number.isFinite(item[freeProperty]) && total > 0) {
  123. result = ((total - item[freeProperty]) / total) * 100;
  124. }
  125. return result.toFixed(1);
  126. },
  127. /**
  128. * hide Host details block
  129. *
  130. * @param {Object} e
  131. * @this App.MainChartsHeatmapHostView
  132. */
  133. mouseLeave: function (e) {
  134. $("#heatmapDetailsBlock").hide();
  135. },
  136. hostTemperatureStyle: function () {
  137. var controller = this.get('controller');
  138. var h2sMap = controller.get('hostToSlotMap');
  139. if (h2sMap) {
  140. var hostname = this.get('content.hostName');
  141. if (hostname) {
  142. var slot = h2sMap[hostname];
  143. if (slot > -1) {
  144. var slotDefs = controller.get('selectedMetric.slotDefinitions');
  145. if (slotDefs && slotDefs.length > slot) {
  146. return slotDefs[slot].get('cssStyle');
  147. }
  148. }
  149. }
  150. }
  151. return '';
  152. }.property('controller.hostToSlotMap')
  153. });