Skip to content

Instantly share code, notes, and snippets.

@zygm0nt
Created September 7, 2012 12:31
Show Gist options
  • Save zygm0nt/3665831 to your computer and use it in GitHub Desktop.
Save zygm0nt/3665831 to your computer and use it in GitHub Desktop.
Ease the pain of Hadoop log reading (on multiple machines) with Chrome User-Script

Important!

Remember to run google-chrome like this, for the time of installing this user script:

$ google-chrome --enable-easy-off-store-extension-install
// ==UserScript==
// @name ShowMeTheLogs
// @namespace hadoop
// @description Show remote jobtracker logs
// @version 0.0.1
// @author mcl_touk.pl
// @license (CC) BY-SA-3.0 http://creativecommons.org/licenses/by-sa/3.0/
// @include http*://localhost:50030/*
// @run-at document-end
// @noframes
// @grant GM_deleteValue
// @grant GM_getValue
// @grant GM_listValues
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
// the guts of this userscript
function main() {
$(document).on("mousedown", "a[href^='http://hadoop']", function(e) {
e.preventDefault();
var href = $(this).attr("href");
var srv_num = href.match(/hadoop(\d)/)[1];
var port_num = 50060 + parseInt(srv_num, 0);
var replacePart = href.substring(0, href.indexOf("/", 10));
href = href.replace(replacePart, "http://localhost:" + port_num);
console.log("altering link to: " + href);
window.location = href;
});
}
// load jQuery and execute the main function
addJQuery(main);
ssh -N -L 50062:localhost:50060 root@hadoop2 &
ssh -N -L 50063:localhost:50060 root@hadoop3 &
ssh -N -L 50064:localhost:50060 root@hadoop4 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment