ksm.js 10 KB

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