ksm.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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', ['ozone', 'nvd3']);
  24. angular.module('ksm').component('ksmMetrics', {
  25. templateUrl: 'ksm-metrics.html',
  26. controller: function ($http) {
  27. var ctrl = this;
  28. ctrl.graphOptions = {
  29. chart: {
  30. type: 'pieChart',
  31. height: 500,
  32. x: function (d) {
  33. return d.key;
  34. },
  35. y: function (d) {
  36. return d.value;
  37. },
  38. showLabels: true,
  39. labelType: 'value',
  40. duration: 500,
  41. labelThreshold: 0.01,
  42. labelSunbeamLayout: true,
  43. legend: {
  44. margin: {
  45. top: 5,
  46. right: 35,
  47. bottom: 5,
  48. left: 0
  49. }
  50. }
  51. }
  52. };
  53. $http.get("/jmx?qry=Hadoop:service=KeySpaceManager,name=KSMMetrics")
  54. .then(function (result) {
  55. var groupedMetrics = {others: [], nums: {}};
  56. var metrics = result.data.beans[0]
  57. for (var key in metrics) {
  58. var numericalStatistic = key.match(/Num([A-Z][a-z]+)(.+?)(Fails)?$/);
  59. if (numericalStatistic) {
  60. var type = numericalStatistic[1];
  61. var name = numericalStatistic[2];
  62. var failed = numericalStatistic[3];
  63. groupedMetrics.nums[type] = groupedMetrics.nums[type] || {
  64. failures: [],
  65. all: []
  66. };
  67. if (failed) {
  68. groupedMetrics.nums[type].failures.push({
  69. key: name,
  70. value: metrics[key]
  71. })
  72. } else {
  73. if (name == "Ops") {
  74. groupedMetrics.nums[type].ops = metrics[key]
  75. } else {
  76. groupedMetrics.nums[type].all.push({
  77. key: name,
  78. value: metrics[key]
  79. })
  80. }
  81. }
  82. } else if (isIgnoredJmxKeys(key)) {
  83. //ignore
  84. } else {
  85. groupedMetrics.others.push({
  86. 'key': key,
  87. 'value': metrics[key]
  88. });
  89. }
  90. }
  91. ctrl.metrics = groupedMetrics;
  92. })
  93. }
  94. });
  95. })();