namenode_cpu.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.NameNodeCpuPieChartView = App.PieChartDashboardWidgetView.extend({
  20. title: Em.I18n.t('dashboard.widgets.NameNodeCpu'),
  21. id: '3',
  22. model_type: 'hdfs',
  23. widgetHtmlId: 'widget-nn-cpu',
  24. cpuWio: null,
  25. nnHostName: "",
  26. intervalId: null,
  27. willDestroyElement: function () {
  28. clearInterval(this.get("intervalId"));
  29. },
  30. didInsertElement: function () {
  31. this._super();
  32. var self = this,
  33. intervalId;
  34. App.router.get('mainController').isLoading.call(App.router.get('clusterController'), 'isServiceContentFullyLoaded').done(function () {
  35. if (App.get('isHaEnabled')) {
  36. self.set('nnHostName', self.get('model.activeNameNode.hostName'));
  37. } else {
  38. self.set('nnHostName', self.get('model.nameNode.hostName'));
  39. }
  40. if (self.get('nnHostName')) {
  41. self.getValue();
  42. intervalId = setInterval(function () {
  43. self.getValue()
  44. }, App.componentsUpdateInterval);
  45. self.set('intervalId', intervalId);
  46. }
  47. });
  48. },
  49. getValue: function () {
  50. App.ajax.send({
  51. name: 'namenode.cpu_wio',
  52. sender: this,
  53. data: {
  54. nnHost: this.get('nnHostName')
  55. },
  56. success: 'updateValueSuccess',
  57. error: 'updateValueError'
  58. });
  59. },
  60. updateValueError: function () {
  61. this.calc();
  62. },
  63. updateValueSuccess: function (response) {
  64. this.set('cpuWio', Em.get(response, 'metrics.cpu.cpu_wio'));
  65. this.calc();
  66. },
  67. calcHiddenInfo: function () {
  68. var value = this.get('cpuWio');
  69. var obj1;
  70. if (value) {
  71. value = value >= 100 ? 100 : value;
  72. obj1 = (value + 0).toFixed(2) + '%';
  73. }
  74. else {
  75. obj1 = Em.I18n.t('services.service.summary.notAvailable');
  76. }
  77. return [
  78. obj1,
  79. 'CPU wait I/O'
  80. ];
  81. },
  82. calcIsPieExists: function () {
  83. return !Em.isNone(this.get('cpuWio'));
  84. },
  85. calcDataForPieChart: function () {
  86. var value = this.get('cpuWio');
  87. value = value >= 100 ? 100 : value;
  88. var percent = (value + 0).toFixed(1);
  89. var percentPrecise = (value + 0).toFixed(2);
  90. return [percent, percentPrecise];
  91. }
  92. });