dfshealth.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 data = {};
  21. function render() {
  22. var helpers = {
  23. 'helper_fs_max_objects': function (chunk, ctx, bodies, params) {
  24. var o = ctx.current();
  25. if (o.MaxObjects > 0) {
  26. chunk.write('(' + Math.round((o.FilesTotal + o.BlockTotal) / o.MaxObjects * 100) * 100 + ')%');
  27. }
  28. },
  29. 'helper_dir_status': function (chunk, ctx, bodies, params) {
  30. var j = ctx.current();
  31. for (var i in j) {
  32. chunk.write('<tr><td>' + i + '</td><td>' + j[i] + '</td><td>' + params.type + '</td></tr>');
  33. }
  34. }
  35. };
  36. var base = dust.makeBase(helpers);
  37. var TEMPLATES = [ { 'name': 'dfshealth', 'url': 'dfshealth.dust.html' } ];
  38. load_templates(dust, TEMPLATES, function() {
  39. dust.render('dfshealth', base.push(data), function(err, out) {
  40. $('#panel').html(out);
  41. });
  42. }, function () {
  43. show_err_msg('Failed to load the page.');
  44. });
  45. }
  46. var BEANS = [
  47. {"name": "nn", "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo"},
  48. {"name": "nnstat", "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus"},
  49. {"name": "fs", "url": "/jmx?qry=Hadoop:service=NameNode,name=FSNamesystemState"},
  50. {"name": "mem", "url": "/jmx?qry=java.lang:type=Memory"},
  51. {"name": "startup", "url": "/startupProgress"}
  52. ];
  53. // Workarounds for the fact that JMXJsonServlet returns non-standard JSON strings
  54. function data_workaround(d) {
  55. function node_map_to_array(nodes) {
  56. var res = [];
  57. for (var n in nodes) {
  58. var p = nodes[n];
  59. p.name = n;
  60. res.push(p);
  61. }
  62. return res;
  63. }
  64. function startup_progress_workaround(r) {
  65. function rename_property(o, s, d) {
  66. if (o[s] !== undefined) {
  67. o[d] = o[s];
  68. delete o[s];
  69. }
  70. }
  71. r.percentComplete *= 100;
  72. $.each(r.phases, function (idx, p) {
  73. p.percentComplete *= 100;
  74. $.each(p.steps, function (idx2, s) {
  75. s.percentComplete *= 100;
  76. // dust.js is confused by these optional keys in nested
  77. // structure, rename them
  78. rename_property(s, "desc", "stepDesc");
  79. rename_property(s, "file", "stepFile");
  80. rename_property(s, "size", "stepSize");
  81. });
  82. });
  83. return r;
  84. }
  85. d.nn.JournalTransactionInfo = JSON.parse(d.nn.JournalTransactionInfo);
  86. d.nn.NameJournalStatus = JSON.parse(d.nn.NameJournalStatus);
  87. d.nn.NameDirStatuses = JSON.parse(d.nn.NameDirStatuses);
  88. d.nn.NodeUsage = JSON.parse(d.nn.NodeUsage);
  89. d.nn.LiveNodes = node_map_to_array(JSON.parse(d.nn.LiveNodes));
  90. d.nn.DeadNodes = node_map_to_array(JSON.parse(d.nn.DeadNodes));
  91. d.nn.DecomNodes = node_map_to_array(JSON.parse(d.nn.DecomNodes));
  92. d.nn.CorruptFiles = JSON.parse(d.nn.CorruptFiles);
  93. d.fs.SnapshotStats = JSON.parse(d.fs.SnapshotStats);
  94. d.startup = startup_progress_workaround(d.startup);
  95. return d;
  96. }
  97. function show_err_msg(msg) {
  98. $('#alert-panel-body').html(msg);
  99. $('#alert-panel').show();
  100. }
  101. load_json(
  102. BEANS,
  103. function(d) {
  104. for (var k in d) {
  105. data[k] = k === "startup" ? d[k] : d[k].beans[0];
  106. }
  107. data = data_workaround(data);
  108. render();
  109. },
  110. function (url, jqxhr, text, err) {
  111. show_err_msg('<p>Failed to retrieve data from ' + url + ', cause: ' + err + '</p>');
  112. });
  113. })();