| 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, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
*/ |
| 19 |
|
| 20 |
var htrace = htrace || {}; |
| 21 |
|
| 22 |
htrace.ServerInfoView = Backbone.View.extend({ |
| 23 |
events: { |
| 24 |
"click .serverConfigurationButton": "showServerConfigurationModal", |
| 25 |
"click .storageDirectoryStatsButton": "showStorageDirectoryStatsModal", |
| 26 |
"click .debugInfoButton": "showDebugInfoModal", |
| 27 |
}, |
| 28 |
|
| 29 |
render: function() { |
| 30 |
this.$el.html(_.template($("#server-info-view-template").html()) |
| 31 |
({ model : this.model, |
| 32 |
view : this})); |
| 33 |
console.log("ServerInfoView#render"); |
| 34 |
return this; |
| 35 |
}, |
| 36 |
|
| 37 |
close: function() { |
| 38 |
console.log("ServerInfoView#close") |
| 39 |
this.undelegateEvents(); |
| 40 |
}, |
| 41 |
|
| 42 |
getServerStatsTableHtml: function() { |
| 43 |
var out = |
| 44 |
'<div class="panel-heading">' + |
| 45 |
'<div class="panel-title">Span Metrics</div>' + |
| 46 |
'</div>' + |
| 47 |
'<table class="table table-striped">' + |
| 48 |
'<thead>' + |
| 49 |
'<tr>' + |
| 50 |
'<th>Remote</th>' + |
| 51 |
'<th>Written</th>' + |
| 52 |
'<th>ServerDropped</th>' + |
| 53 |
'</tr>' + |
| 54 |
'</thead>'; |
| 55 |
var remotes = []; |
| 56 |
var stats = this.model.stats |
| 57 |
var spanMetrics = stats.get("HostSpanMetrics") |
| 58 |
for (var remote in spanMetrics) { |
| 59 |
if (spanMetrics.hasOwnProperty(remote)) { |
| 60 |
remotes.push(remote) |
| 61 |
} |
| 62 |
} |
| 63 |
remotes = remotes.sort() |
| 64 |
for (var i = 0; i < remotes.length; i++) { |
| 65 |
var remote = remotes[i]; |
| 66 |
var smtx = spanMetrics[remote]; |
| 67 |
out = out + "<tr>" + |
| 68 |
"<td>" + remote + "</td>" + |
| 69 |
"<td>" + smtx.Written + "</td>" + |
| 70 |
"<td>" + smtx.ServerDropped + "</td>" + |
| 71 |
"</tr>"; |
| 72 |
} |
| 73 |
out = out + '</table>'; |
| 74 |
//console.log("out = " + out); |
| 75 |
return out; |
| 76 |
}, |
| 77 |
|
| 78 |
showServerConfigurationModal: function() { |
| 79 |
var config = new htrace.ServerConfiguration(); |
| 80 |
var view = this; |
| 81 |
config.fetch({ |
| 82 |
"error": function(model, response, options) { |
| 83 |
window.alert("Failed to fetch htraced server configuration: " + |
| 84 |
JSON.stringify(response)); |
| 85 |
}, |
| 86 |
"success": function(model, response, options) { |
| 87 |
var confKeys = []; |
| 88 |
for (var confKey in model.attributes) { |
| 89 |
confKeys.push(confKey) |
| 90 |
} |
| 91 |
console.log("confKeys = " + JSON.stringify(confKeys)); |
| 92 |
confKeys = confKeys.sort() |
| 93 |
var out = '<table style="table-layout:fixed;width:100%;word-wrap:break-word">' + |
| 94 |
'<thead>' + |
| 95 |
'<tr>' + |
| 96 |
'<th>Key</th>' + |
| 97 |
'<th>Value</th>' + |
| 98 |
'</tr>' + |
| 99 |
'</thead>'; |
| 100 |
for (var i = 0; i < confKeys.length; i++) { |
| 101 |
var colorString = ((i%2) == 1) ? "#f1f1f1" : "#ffffff"; |
| 102 |
out += _.template($("#table-row-template").html())( |
| 103 |
{bgcolor: colorString, key: confKeys[i], |
| 104 |
val: model.attributes[confKeys[i]]}); |
| 105 |
//out = out + '<tr><th>' + confKeys[i] + '</th><th>' + |
| 106 |
//model.attributes[confKeys[i]] + '</th></tr>'; |
| 107 |
} |
| 108 |
var out = out + '</table>'; |
| 109 |
htrace.showModal(_.template($("#modal-table-template").html())( |
| 110 |
{title: "HTraced Server Configuration", body: out})); |
| 111 |
} |
| 112 |
}) |
| 113 |
}, |
| 114 |
|
| 115 |
showStorageDirectoryStatsModal: function() { |
| 116 |
var dirs = this.model.stats.get("Dirs"); |
| 117 |
var out = ""; |
| 118 |
for (var dirIdx = 0; dirIdx < dirs.length; dirIdx++) { |
| 119 |
var dir = dirs[dirIdx]; |
| 120 |
out += "<h3>" + dir.Path + "</h3>"; |
| 121 |
out += "Approximate size in bytes: " + dir.ApproximateBytes + "<br/>"; |
| 122 |
out += "<pre>" + dir.LevelDbStats + "</pre></pre><br/><p/>"; |
| 123 |
} |
| 124 |
htrace.showModal(_.template($("#modal-table-template").html())( |
| 125 |
{title: "HTraced Storage Directory Statistics", body: out})); |
| 126 |
}, |
| 127 |
|
| 128 |
showDebugInfoModal: function() { |
| 129 |
var config = new htrace.ServerDebugInfo(); |
| 130 |
var view = this; |
| 131 |
config.fetch({ |
| 132 |
"error": function(model, response, options) { |
| 133 |
window.alert("Failed to fetch htraced server debug info: " + |
| 134 |
JSON.stringify(response)); |
| 135 |
}, |
| 136 |
"success": function(model, response, options) { |
| 137 |
var out = ""; |
| 138 |
out += "<h2>Stack Traces</h2>"; |
| 139 |
out += "<pre>" + model.get("StackTraces") + "</pre>"; |
| 140 |
out += "<h2>GC Stats</h2>"; |
| 141 |
out += "<pre>" + model.get("GCStats") + "</pre>"; |
| 142 |
htrace.showModal(_.template($("#modal-table-template").html())( |
| 143 |
{title: "HTraced Debug Info", body: out})); |
| 144 |
} |
| 145 |
}) |
| 146 |
} |
| 147 |
}); |