test_jmx_parsing.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. $GLOBALS["HDP_MON_DEBUG_MODE"] = FALSE;
  20. $pwd = exec("pwd");
  21. $GLOBALS["HDP_MON_CLUSTER_CONFIG_LOCATION"] = $pwd
  22. ."/data/cluster_configuration.json";
  23. include_once("../../../src/dataServices/common/common.inc");
  24. include_once("../../../src/dataServices/common/cluster_configuration.inc");
  25. include_once("../../../src/dataServices/common/response.inc");
  26. include_once("../../../src/dataServices/jmx/hdp_mon_jmx_helpers.inc");
  27. function verify_hdfs_info($info) {
  28. assert(is_array($info));
  29. assert($info["service_type"] === "HDFS");
  30. assert($info["installed"]);
  31. assert($info["namenode_addr"] == "namenode:50070");
  32. assert($info["secondary_namenode_addr"] == "snamenode:50071");
  33. assert($info["total_nodes"] == 10);
  34. assert($info["memory_heap_used"] == 529321952);
  35. assert($info["memory_heap_max"] == 1006632960);
  36. assert($info["dfs_dirfiles_count"] == 554);
  37. assert($info["dfs_blocks_total"] == 458);
  38. assert($info["dfs_blocks_underreplicated"] == 0);
  39. assert($info["dfs_blocks_missing"] == 0);
  40. assert($info["dfs_blocks_corrupt"] == 0);
  41. assert($info["dfs_state"] == "Operational");
  42. assert($info["start_time"] == 1327557522);
  43. assert($info["live_nodes"] == 10);
  44. assert($info["dead_nodes"] == 1);
  45. assert($info["decommissioning_nodes"] == 0);
  46. assert($info["version"] == "1.0.0");
  47. assert($info["safemode"] == TRUE);
  48. assert($info["pending_upgrades"] == "");
  49. assert($info["dfs_configured_capacity"] == 36336891658240);
  50. assert($info["dfs_percent_used"] == 0);
  51. assert($info["dfs_percent_remaining"] == 99.08);
  52. assert($info["dfs_total_bytes"] == 36336891658240);
  53. assert($info["dfs_used_bytes"] == 1750237184);
  54. assert($info["nondfs_used_bytes"] == 331691536384);
  55. assert($info["dfs_free_bytes"] == 36003449884672);
  56. assert($info["safemode_reason"] != "");
  57. }
  58. function verify_mr_info($info) {
  59. assert(is_array($info));
  60. assert($info["service_type"] === "MAPREDUCE");
  61. assert($info["installed"]);
  62. assert($info["jobtracker_addr"] == "jobtracker:50030");
  63. assert($info["trackers_total"] == 20);
  64. assert($info["jobhistory_addr"] == "jobhistory_host:52890");
  65. assert($info["memory_heap_used"] == 158277552);
  66. assert($info["memory_heap_max"] == 1052770304);
  67. assert($info["trackers_live"] == 10);
  68. assert($info["trackers_graylisted"] == 0);
  69. assert($info["trackers_blacklisted"] == 0);
  70. assert($info["version"] == "1.0.0, r1224962");
  71. assert(is_array($info["queue_info"])
  72. && $info["queue_info"]["type"] == "CapacityTaskScheduler"
  73. && count($info["queue_info"]["queues"]) == 1);
  74. assert($info["queue_info"]["queues"]["default"]["state"] == "running"
  75. && $info["queue_info"]["queues"]["default"]["capacity_percentage"]
  76. == 100.0
  77. && $info["queue_info"]["queues"]["default"]["user_limit"] == 100
  78. && $info["queue_info"]["queues"]["default"]["priority_supported"] == 1
  79. && $info["queue_info"]["queues"]["default"]["map_capacity"] == 40
  80. && $info["queue_info"]["queues"]["default"]["map_running_tasks"] == 0
  81. && $info["queue_info"]["queues"]["default"]["reduce_capacity"] == 20
  82. && $info["queue_info"]["queues"]["default"]["reduce_running_tasks"] == 0
  83. && $info["queue_info"]["queues"]["default"]["waiting_jobs"] == 3
  84. && $info["queue_info"]["queues"]["default"]["initializing_jobs"] == 0
  85. && $info["queue_info"]["queues"]["default"]["users_with_submitted_jobs"]
  86. == 0);
  87. assert($info["trackers_excluded"] == 0);
  88. assert($info["map_task_capacity"] == 40);
  89. assert($info["reduce_task_capacity"] == 20);
  90. assert($info["job_total_submissions"] == 105);
  91. assert($info["job_total_completions"] == 104);
  92. assert($info["running_jobs"] == 0);
  93. assert($info["waiting_jobs"] == 3);
  94. assert($info["running_map_tasks"] == 0);
  95. assert($info["running_reduce_tasks"] == 0);
  96. assert($info["occupied_map_slots"] == 0);
  97. assert($info["occupied_reduce_slots"] == 0);
  98. assert($info["reserved_map_slots"] == 0);
  99. assert($info["reserved_reduce_slots"] == 0);
  100. assert($info["waiting_maps"] == 1);
  101. assert($info["waiting_reduces"] == 0);
  102. assert($info["start_time"] == 1327557546);
  103. assert($info["average_node_capacity"] == 6);
  104. }
  105. function verify_hbase_info($info) {
  106. assert(is_array($info));
  107. assert($info["service_type"] === "HBASE");
  108. assert($info["installed"]);
  109. assert($info["total_regionservers"] === 30);
  110. assert($info["memory_heap_used"] === 32946880);
  111. assert($info["memory_heap_max"] === 1035468800);
  112. assert($info["cluster_id"] === "d24914d7-75d3-4dcc-9e6f-0d7770833993");
  113. assert($info["start_time"] == 1329244267);
  114. assert($info["active_time"] == 1329244269);
  115. assert(is_array($info["coprocessors"])
  116. && count($info["coprocessors"]) == 0);
  117. assert($info["average_load"] == 2);
  118. assert($info["regions_in_transition_count"] === 0);
  119. assert($info["live_regionservers"] === 1);
  120. assert($info["dead_regionservers"] === 0);
  121. assert(is_array($info["zookeeper_quorum"])
  122. && count($info["zookeeper_quorum"]) == 1
  123. && $info["zookeeper_quorum"][0] === "localhost:2181");
  124. assert($info["version"] ===
  125. "0.92.1-SNAPSHOT, ra23f8636efd6dd9d37f3a15d83f2396819509502");
  126. }
  127. function verify_overall_info($info) {
  128. assert(is_array($info));
  129. assert(is_array($info["overall"]));
  130. assert(is_array($info["hbase"]));
  131. assert(is_array($info["hdfs"]));
  132. assert(is_array($info["mapreduce"]));
  133. assert($info["overall"]["ganglia_url"] ==
  134. "http://gangliaweb_host:80/var/www/ganglia2");
  135. assert($info["overall"]["nagios_url"] == "http://nagiosserver_host:80/nagios");
  136. assert($info["overall"]["hdfs_installed"] == 1);
  137. assert($info["overall"]["mapreduce_installed"] == 1);
  138. assert($info["overall"]["hbase_installed"] == 1);
  139. assert($info["overall"]["namenode_addr"] == "namenode:50070");
  140. assert($info["overall"]["secondary_namenode_addr"] == "snamenode:50071");
  141. assert($info["overall"]["namenode_starttime"] == 1327557522);
  142. assert($info["overall"]["total_nodes"] == 10);
  143. assert($info["overall"]["live_nodes"] == 10);
  144. assert($info["overall"]["dead_nodes"] == 1);
  145. assert($info["overall"]["decommissioning_nodes"] == 0);
  146. assert($info["overall"]["dfs_blocks_underreplicated"] == 0);
  147. assert($info["overall"]["safemode"] == TRUE);
  148. assert($info["overall"]["pending_upgrades"] == "");
  149. assert($info["overall"]["dfs_configured_capacity"] == 36336891658240);
  150. assert($info["overall"]["dfs_percent_used"] == 0);
  151. assert($info["overall"]["dfs_percent_remaining"] == 99.08);
  152. assert($info["overall"]["dfs_total_bytes"] == 36336891658240);
  153. assert($info["overall"]["dfs_used_bytes"] == 1750237184);
  154. assert($info["overall"]["nondfs_used_bytes"] == 331691536384);
  155. assert($info["overall"]["dfs_free_bytes"] == 36003449884672);
  156. assert($info["overall"]["jobtracker_addr"] == "jobtracker:50030");
  157. assert($info["overall"]["jobtracker_starttime"] == 1327557546);
  158. assert($info["overall"]["running_jobs"] == 0);
  159. assert($info["overall"]["waiting_jobs"] == 3);
  160. assert($info["overall"]["trackers_total"] == 20);
  161. assert($info["overall"]["trackers_live"] == 10);
  162. assert($info["overall"]["trackers_graylisted"] == 0);
  163. assert($info["overall"]["trackers_blacklisted"] == 0);
  164. assert($info["overall"]["hbasemaster_addr"] == "hbasemaster:60010");
  165. assert($info["overall"]["total_regionservers"] == 30);
  166. assert($info["overall"]["hbasemaster_starttime"] == 1329244267);
  167. assert($info["overall"]["live_regionservers"] == 1);
  168. assert($info["overall"]["dead_regionservers"] == 0);
  169. assert($info["overall"]["regions_in_transition_count"] == 0);
  170. assert($info["hdfs"]["namenode_addr"] == "namenode:50070");
  171. assert($info["hdfs"]["secondary_namenode_addr"] == "snamenode:50071");
  172. assert($info["hdfs"]["namenode_starttime"] == 1327557522);
  173. assert($info["hdfs"]["total_nodes"] == 10);
  174. assert($info["hdfs"]["live_nodes"] == 10);
  175. assert($info["hdfs"]["dead_nodes"] == 1);
  176. assert($info["hdfs"]["decommissioning_nodes"] == 0);
  177. assert($info["hdfs"]["dfs_blocks_underreplicated"] == 0);
  178. assert($info["hdfs"]["safemode"] == TRUE);
  179. assert($info["hdfs"]["pending_upgrades"] == "");
  180. assert($info["hdfs"]["dfs_configured_capacity"] == 36336891658240);
  181. assert($info["hdfs"]["dfs_percent_used"] == 0);
  182. assert($info["hdfs"]["dfs_percent_remaining"] == 99.08);
  183. assert($info["hdfs"]["dfs_total_bytes"] == 36336891658240);
  184. assert($info["hdfs"]["dfs_used_bytes"] == 1750237184);
  185. assert($info["hdfs"]["nondfs_used_bytes"] == 331691536384);
  186. assert($info["hdfs"]["dfs_free_bytes"] == 36003449884672);
  187. assert($info["mapreduce"]["jobtracker_addr"] == "jobtracker:50030");
  188. assert($info["mapreduce"]["jobtracker_starttime"] == 1327557546);
  189. assert($info["mapreduce"]["running_jobs"] == 0);
  190. assert($info["mapreduce"]["waiting_jobs"] == 3);
  191. assert($info["mapreduce"]["trackers_total"] == 20);
  192. assert($info["mapreduce"]["trackers_live"] == 10);
  193. assert($info["mapreduce"]["trackers_graylisted"] == 0);
  194. assert($info["mapreduce"]["trackers_blacklisted"] == 0);
  195. assert($info["hbase"]["hbasemaster_addr"] == "hbasemaster:60010");
  196. assert($info["hbase"]["total_regionservers"] == 30);
  197. assert($info["hbase"]["hbasemaster_starttime"] == 1329244267);
  198. assert($info["hbase"]["live_regionservers"] == 1);
  199. assert($info["hbase"]["dead_regionservers"] == 0);
  200. assert($info["hbase"]["regions_in_transition_count"] == 0);
  201. }
  202. hdp_mon_load_cluster_configuration();
  203. if (!isset($GLOBALS["HDP_MON_CONFIG"])) {
  204. error_log("global CONFIG is still not set");
  205. exit(1);
  206. }
  207. $hdfs_jmx_json = file_get_contents("./data/sample_namenode_jmx.json");
  208. if (!$hdfs_jmx_json || $hdfs_jmx_json == "") {
  209. error_log("Invalid json data for namenode jmx");
  210. exit(1);
  211. }
  212. $hdfsinfo = hdp_mon_jmx_parse_hdfs_info(json_decode($hdfs_jmx_json, true));
  213. verify_hdfs_info($hdfsinfo);
  214. $mr_jmx_json = file_get_contents("./data/sample_jobtracker_jmx.json");
  215. if (!$mr_jmx_json || $mr_jmx_json == "") {
  216. error_log("Invalid json data for jobtracker jmx");
  217. exit(1);
  218. }
  219. $mrinfo = hdp_mon_jmx_parse_mapreduce_info(json_decode($mr_jmx_json, true));
  220. verify_mr_info($mrinfo);
  221. $hbase_jmx_json = file_get_contents("./data/sample_hbasemaster_jmx.json");
  222. if (!$hbase_jmx_json || $hbase_jmx_json == "") {
  223. error_log("Invalid json data for hbase master jmx");
  224. exit(1);
  225. }
  226. $hbaseinfo = hdp_mon_jmx_parse_hbase_info(json_decode($hbase_jmx_json, true));
  227. verify_hbase_info($hbaseinfo);
  228. $overallinfo = hdp_mon_helper_get_cluster_info($hdfsinfo,
  229. $mrinfo, $hbaseinfo);
  230. verify_overall_info($overallinfo);
  231. ?>