ozone.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. (function () {
  19. "use strict";
  20. var isIgnoredJmxKeys = function (key) {
  21. return key == 'name' || key == 'modelerType' || key == "$$hashKey" ||
  22. key.match(/tag.*/);
  23. };
  24. angular.module('ozone', ['nvd3'])
  25. angular.module('ozone').component('overview', {
  26. templateUrl: 'static/templates/overview.html',
  27. transclude: true,
  28. controller: function ($http) {
  29. var ctrl = this;
  30. $http.get("/jmx?qry=Hadoop:service=*,name=*,component=ServerRuntime")
  31. .then(function (result) {
  32. ctrl.jmx = result.data.beans[0]
  33. })
  34. }
  35. });
  36. angular.module('ozone').component('jvmParameters', {
  37. templateUrl: 'static/templates/jvm.html',
  38. controller: function ($http) {
  39. var ctrl = this
  40. $http.get("/jmx?qry=java.lang:type=Runtime")
  41. .then(function (result) {
  42. ctrl.jmx = result.data.beans[0];
  43. //convert array to a map
  44. var systemProperties = {}
  45. for (var idx in ctrl.jmx.SystemProperties) {
  46. var item = ctrl.jmx.SystemProperties[idx];
  47. systemProperties[item.key.replace(/\./g, "_")] = item.value;
  48. }
  49. ctrl.jmx.SystemProperties = systemProperties;
  50. })
  51. }
  52. });
  53. angular.module('ozone').component('rpcMetrics', {
  54. template: '<h1>Rpc metrics</h1><tabs>' +
  55. '<pane ng-repeat="metric in $ctrl.metrics" ' +
  56. 'title="Port {{metric[\'tag.port\']}}">' +
  57. '<rpc-metric jmxdata="metric"></rpc-metric></pane>' +
  58. '</tabs>',
  59. controller: function ($http) {
  60. var ctrl = this;
  61. $http.get("/jmx?qry=Hadoop:service=*,name=RpcActivityForPort*")
  62. .then(function (result) {
  63. ctrl.metrics = result.data.beans;
  64. })
  65. }
  66. });
  67. angular.module('ozone').component('rpcMetric', {
  68. bindings: {
  69. jmxdata: '<'
  70. },
  71. templateUrl: 'static/templates/rpc-metrics.html',
  72. controller: function () {
  73. var ctrl = this;
  74. ctrl.percentileGraphOptions = {
  75. chart: {
  76. type: 'discreteBarChart',
  77. height: 450,
  78. margin: {
  79. top: 20,
  80. right: 20,
  81. bottom: 50,
  82. left: 55
  83. },
  84. x: function (d) {
  85. return d.label;
  86. },
  87. y: function (d) {
  88. return d.value;
  89. },
  90. showValues: true,
  91. valueFormat: function (d) {
  92. return d3.format(',.1f')(d);
  93. },
  94. duration: 500,
  95. xAxis: {
  96. axisLabel: 'Percentage'
  97. },
  98. yAxis: {
  99. axisLabel: 'Latency (ms)',
  100. axisLabelDistance: -10
  101. }
  102. }
  103. };
  104. ctrl.$onChanges = function (data) {
  105. var groupedMetrics = {}
  106. var createPercentageMetrics = function (metricName, window) {
  107. groupedMetrics.percentiles = groupedMetrics['percentiles'] || {}
  108. groupedMetrics.percentiles[metricName] = groupedMetrics.percentiles[metricName] || {};
  109. groupedMetrics.percentiles[metricName][window] = groupedMetrics.percentiles[metricName][window] || {
  110. graphdata: [{
  111. key: window,
  112. values: []
  113. }], numOps: 0
  114. };
  115. };
  116. var metrics = ctrl.jmxdata;
  117. for (var key in metrics) {
  118. var percentile = key.match(/(.*Time)(\d+s)(\d+th)PercentileLatency/);
  119. var percentileNumOps = key.match(/(.*Time)(\d+s)NumOps/);
  120. var successFailures = key.match(/(.*)(Success|Failures)/);
  121. var numAverages = key.match(/(.*Time)(NumOps|AvgTime)/);
  122. if (percentile) {
  123. var metricName = percentile[1];
  124. var window = percentile[2];
  125. var percentage = percentile[3]
  126. createPercentageMetrics(metricName, window);
  127. groupedMetrics.percentiles[metricName][window].graphdata[0]
  128. .values.push({
  129. label: percentage,
  130. value: metrics[key]
  131. })
  132. } else if (successFailures) {
  133. var metricName = successFailures[1];
  134. groupedMetrics.successfailures = groupedMetrics['successfailures'] || {}
  135. groupedMetrics.successfailures[metricName] = groupedMetrics.successfailures[metricName] || {
  136. success: 0,
  137. failures: 0
  138. };
  139. if (successFailures[2] == 'Success') {
  140. groupedMetrics.successfailures[metricName].success = metrics[key];
  141. } else {
  142. groupedMetrics.successfailures[metricName].failures = metrics[key];
  143. }
  144. } else if (numAverages) {
  145. var metricName = numAverages[1];
  146. groupedMetrics.numavgs = groupedMetrics['numavgs'] || {}
  147. groupedMetrics.numavgs[metricName] = groupedMetrics.numavgs[metricName] || {
  148. numOps: 0,
  149. avgTime: 0
  150. };
  151. if (numAverages[2] == 'NumOps') {
  152. groupedMetrics.numavgs[metricName].numOps = metrics[key];
  153. } else {
  154. groupedMetrics.numavgs[metricName].avgTime = metrics[key];
  155. }
  156. } else if (percentileNumOps) {
  157. var metricName = percentileNumOps[1];
  158. var window = percentileNumOps[2];
  159. createPercentageMetrics(metricName, window);
  160. groupedMetrics.percentiles[metricName][window].numOps = metrics[key];
  161. } else if (isIgnoredJmxKeys(key)) {
  162. //ignore
  163. } else {
  164. groupedMetrics.others = groupedMetrics.others || [];
  165. groupedMetrics.others.push({
  166. 'key': key,
  167. 'value': metrics[key]
  168. });
  169. }
  170. }
  171. ctrl.metrics = groupedMetrics;
  172. };
  173. }
  174. });
  175. angular.module('ozone')
  176. .component('tabs', {
  177. transclude: true,
  178. controller: function ($scope) {
  179. var ctrl = this;
  180. var panes = this.panes = [];
  181. this.select = function (pane) {
  182. angular.forEach(panes, function (pane) {
  183. pane.selected = false;
  184. });
  185. pane.selected = true;
  186. };
  187. this.addPane = function (pane) {
  188. if (panes.length === 0) {
  189. this.select(pane);
  190. }
  191. panes.push(pane);
  192. };
  193. this.click = function(pane) {
  194. ctrl.select(pane);
  195. }
  196. },
  197. template: '<div class="nav navtabs"><div class="container"><ul class="nav nav-pills">' +
  198. '<li ng-repeat="pane in $ctrl.panes" ng-class="{active:pane.selected}">' +
  199. '<a href="" ng-click="$ctrl.click(pane)">{{pane.title}}</a> ' +
  200. '</li> </ul></div><br/><div class="tab-content" ng-transclude></div> </div>'
  201. })
  202. .component('pane', {
  203. transclude: true,
  204. require: {
  205. tabsCtrl: '^tabs'
  206. },
  207. bindings: {
  208. title: '@'
  209. },
  210. controller: function () {
  211. this.$onInit = function () {
  212. this.tabsCtrl.addPane(this);
  213. };
  214. },
  215. template: '<div class="tab-pane" ng-if="$ctrl.selected" ng-transclude></div>'
  216. });
  217. angular.module('ozone').component('commonTools', {
  218. templateUrl: '/static/templates/tools.html',
  219. controller: function ($http) {
  220. var ctrl = this;
  221. ctrl.docs = false;
  222. $http.head("/docs/index.html")
  223. .then(function (result) {
  224. ctrl.docs = true;
  225. },function(){
  226. ctrl.docs = false;
  227. });
  228. }
  229. });
  230. })();