Skip to content

Commit

Permalink
Merge pull request #934 from mattrjacobs/backport-pr-919
Browse files Browse the repository at this point in the history
Dashboard: 2 listeners to same EventSource
  • Loading branch information
mattrjacobs committed Oct 14, 2015
2 parents baeeb24 + 1ea4537 commit 64b65c3
Showing 1 changed file with 28 additions and 65 deletions.
93 changes: 28 additions & 65 deletions hystrix-dashboard/src/main/webapp/monitor/monitor.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,19 @@ <h2><span id="title_name"></span></h2>



<script>
<script>
/**
* Queue up the monitor to start once the page has finished loading.
*
* This is an inline script and expects to execute once on page load.
*/

// commands
var hystrixMonitor = new HystrixCommandMonitor('dependencies', {includeDetailIcon:false});

var dependencyThreadPoolMonitor = new HystrixThreadPoolMonitor('dependencyThreadPools');

var stream = getUrlVars()["stream"];

if(stream != undefined) {
if(getUrlVars()["delay"] != undefined) {
stream = stream + "&delay=" + getUrlVars()["delay"];
Expand All @@ -99,30 +100,31 @@ <h2><span id="title_name"></span></h2>
$('#title_name').text("Hystrix Stream: " + decodeURIComponent(stream))
}

//do not show authorization in stream title
if(getUrlVars()["authorization"] != undefined) {
stream = stream + "&authorization=" + getUrlVars()["authorization"];
}
//do not show authorization in stream title
if(getUrlVars()["authorization"] != undefined) {
stream = stream + "&authorization=" + getUrlVars()["authorization"];
}

var commandStream = "../proxy.stream?origin=" + stream;
var poolStream = "../proxy.stream?origin=" + stream;
var proxyStream = "../proxy.stream?origin=" + stream;
}

$(window).load(function() { // within load with a setTimeout to prevent the infinite spinner
setTimeout(function() {
if(commandStream == undefined) {
console.log("commandStream is undefined")
if(proxyStream == undefined) {
console.log("proxyStream is undefined")
$("#dependencies .loading").html("The 'stream' argument was not provided.");
$("#dependencies .loading").addClass("failed");
} else {
// sort by error+volume by default
hystrixMonitor.sortByErrorThenVolume();

dependencyThreadPoolMonitor.sortByVolume();

// start the EventSource which will open a streaming connection to the server
var source = new EventSource(commandStream);
var source = new EventSource(proxyStream);

// add the listener that will process incoming events
source.addEventListener('message', hystrixMonitor.eventSourceMessageListener, false);
source.addEventListener('message', dependencyThreadPoolMonitor.eventSourceMessageListener, false);

// source.addEventListener('open', function(e) {
// console.console.log(">>> opened connection, phase: " + e.eventPhase);
Expand All @@ -142,59 +144,20 @@ <h2><span id="title_name"></span></h2>
}
},0);
});

// thread pool
var dependencyThreadPoolMonitor = new HystrixThreadPoolMonitor('dependencyThreadPools');

$(window).load(function() { // within load with a setTimeout to prevent the infinite spinner
setTimeout(function() {
if(poolStream == undefined) {
console.log("poolStream is undefined")
$("#dependencyThreadPools .loading").html("The 'stream' argument was not provided.");
$("#dependencyThreadPools .loading").addClass("failed");
} else {
dependencyThreadPoolMonitor.sortByVolume();

// start the EventSource which will open a streaming connection to the server
var source = new EventSource(poolStream);

// add the listener that will process incoming events
source.addEventListener('message', dependencyThreadPoolMonitor.eventSourceMessageListener, false);

// source.addEventListener('open', function(e) {
// console.console.log(">>> opened connection, phase: " + e.eventPhase);
// // Connection was opened.
// }, false);

source.addEventListener('error', function(e) {
$("#dependencyThreadPools .loading").html("Unable to connect to Thread Pool Metric Stream.");
$("#dependencyThreadPools .loading").addClass("failed");
if (e.eventPhase == EventSource.CLOSED) {
// Connection was closed.
console.log("Connection was closed on error: " + e);
} else {
console.log("Error occurred while streaming: " + e);
}
}, false);
}
},0);
});

//Read a page's GET URL variables and return them as an associative array.
// from: http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
function getUrlVars() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}

</script>


Expand Down

0 comments on commit 64b65c3

Please sign in to comment.