host.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. var misc = require('utils/misc');
  20. App.Host = DS.Model.extend({
  21. hostName: DS.attr('string'),
  22. publicHostName: DS.attr('string'),
  23. cluster: DS.belongsTo('App.Cluster'),
  24. hostComponents: DS.hasMany('App.HostComponent'),
  25. cpu: DS.attr('string'),
  26. memory: DS.attr('string'),
  27. diskTotal: DS.attr('number'),
  28. diskFree: DS.attr('number'),
  29. osArch: DS.attr('string'),
  30. ip: DS.attr('string'),
  31. rack: DS.attr('string'),
  32. healthStatus: DS.attr('string'),
  33. lastHeartBeatTime: DS.attr('number'),
  34. osType: DS.attr("string"),
  35. diskInfo: DS.attr('object'),
  36. loadOne:DS.attr('number'),
  37. loadFive:DS.attr('number'),
  38. loadFifteen:DS.attr('number'),
  39. memTotal:DS.attr('number'),
  40. memFree:DS.attr('number'),
  41. cpuSystem:DS.attr('number'),
  42. cpuUser:DS.attr('number'),
  43. cpuUsage: function () {
  44. if (this.get('cpuSystem') && this.get('cpu_user')) {
  45. return this.get('cpuSystem') + this.get('cpu_user');
  46. }
  47. }.property('cpuSystem', 'cpuUser'),
  48. memoryUsage: function () {
  49. if (this.get('memFree') && this.get('memTotal')) {
  50. var memUsed = this.get('memTotal') - this.get('memFree');
  51. return (100 * memUsed) / this.get('memTotal');
  52. }
  53. }.property('memTotal', 'memFree'),
  54. criticalAlertsCount: function () {
  55. return App.router.get('clusterController.alerts').filterProperty('hostName', this.get('hostName')).filterProperty('isOk', false).filterProperty('ignoredForHosts', false).length;
  56. }.property('App.router.clusterController.alerts.length'),
  57. publicHostNameFormatted: function() {
  58. return this.get('publicHostName').length < 43 ? this.get('publicHostName') : this.get('publicHostName').substr(0, 40) + '...';
  59. }.property('publicHostName'),
  60. /**
  61. * API return diskTotal and diskFree. Need to save their different
  62. */
  63. diskUsed: function(){
  64. return this.get('diskTotal') - this.get('diskFree');
  65. }.property('diskFree', 'diskTotal'),
  66. /**
  67. * Format diskUsed value to float with 2 digits (also convert to GB)
  68. */
  69. diskUsedFormatted: function() {
  70. return Math.round(this.get('diskUsed') * Math.pow(10, 2)) / Math.pow(10, 2) + 'GB';
  71. }.property('diskUsed'),
  72. /**
  73. * Format diskTotal value to float with 2 digits (also convert to GB)
  74. */
  75. diskTotalFormatted: function() {
  76. return Math.round(this.get('diskTotal') * Math.pow(10, 2)) / Math.pow(10, 2) + 'GB';
  77. }.property('diskTotal'),
  78. /**
  79. * Percent value of used disk space
  80. */
  81. diskUsage: function() {
  82. return (this.get('diskUsed')) / this.get('diskTotal') * 100;
  83. }.property('diskUsed', 'diskTotal'),
  84. /**
  85. * Format diskUsage to float with 2 digits
  86. */
  87. diskUsageFormatted: function() {
  88. if (isNaN(this.get('diskUsage')) || this.get('diskUsage') < 0) {
  89. return 'Data Unavailable';
  90. }
  91. var s = Math.round(this.get('diskUsage') * Math.pow(10, 2)) / Math.pow(10, 2);
  92. if (isNaN(s)) {
  93. s = 0;
  94. }
  95. return s + '%';
  96. }.property('diskUsage'),
  97. diskInfoBar: function() {
  98. if (isNaN(this.get('diskUsage')) || this.get('diskUsage') < 0) {
  99. return this.get('diskUsageFormatted');
  100. }
  101. return this.get('diskUsedFormatted') + '/' + this.get('diskTotalFormatted') + ' (' + this.get('diskUsageFormatted')
  102. + ' ' + Em.I18n.t('services.service.summary.diskInfoBar.used') + ')';
  103. }.property('diskUsedFormatted', 'diskTotalFormatted'),
  104. /**
  105. * formatted bytes to appropriate value
  106. */
  107. memoryFormatted: function () {
  108. return misc.formatBandwidth(this.get('memory') * 1024);
  109. }.property('memory'),
  110. /**
  111. * Return true if the host has not sent heartbeat within the last 180 seconds
  112. */
  113. isNotHeartBeating : function() {
  114. return (App.testMode) ? false : ((new Date()).getTime() - this.get('lastHeartBeatTime')) > 180 * 1000;
  115. }.property('lastHeartBeatTime'),
  116. loadAvg: function() {
  117. if (this.get('loadOne') != null) return this.get('loadOne').toFixed(2);
  118. if (this.get('loadFive') != null) return this.get('loadFive').toFixed(2);
  119. if (this.get('loadFifteen') != null) return this.get('loadFifteen').toFixed(2);
  120. }.property('loadOne', 'loadFive', 'loadFifteen'),
  121. healthClass: function(){
  122. var statusMap = {
  123. 'UNKNOWN': 'health-status-DEAD-YELLOW',
  124. 'HEALTHY': 'health-status-LIVE',
  125. 'UNHEALTHY': 'health-status-DEAD-RED',
  126. 'ALERT': 'health-status-DEAD-ORANGE'
  127. };
  128. return statusMap[this.get('healthStatus')] || 'health-status-DEAD-YELLOW';
  129. }.property('healthStatus'),
  130. healthToolTip: function(){
  131. var hostComponents = this.get('hostComponents').filter(function(item){
  132. if(item.get('workStatus') !== App.HostComponentStatus.started){
  133. return true;
  134. }
  135. });
  136. var output = '';
  137. switch (this.get('healthClass')){
  138. case 'health-status-DEAD-RED':
  139. hostComponents = hostComponents.filterProperty('isMaster', true);
  140. output = Em.I18n.t('hosts.host.healthStatus.mastersDown');
  141. hostComponents.forEach(function(hc, index){
  142. output += (index == (hostComponents.length-1)) ? hc.get('displayName') : (hc.get('displayName')+", ");
  143. }, this);
  144. break;
  145. case 'health-status-DEAD-YELLOW':
  146. output = Em.I18n.t('hosts.host.healthStatus.heartBeatNotReceived');
  147. break;
  148. case 'health-status-DEAD-ORANGE':
  149. hostComponents = hostComponents.filterProperty('isSlave', true);
  150. output = Em.I18n.t('hosts.host.healthStatus.slavesDown');
  151. hostComponents.forEach(function(hc, index){
  152. output += (index == (hostComponents.length-1)) ? hc.get('displayName') : (hc.get('displayName')+", ");
  153. }, this);
  154. break;
  155. case 'health-status-LIVE':
  156. output = Em.I18n.t('hosts.host.healthStatus.allUp');
  157. break;
  158. }
  159. return output;
  160. }.property('hostComponents.@each.workStatus')
  161. });
  162. App.Host.FIXTURES = [];