ozoneManager.js 4.3 KB

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