Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard: 2 listeners to same EventSource #934

Merged
merged 2 commits into from
Oct 14, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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