Skip to content

Commit 6c048a3

Browse files
author
Oli McCormack
committed
Allow settings via url parameters.
Support specifying host/refreshInterval via url arguments. Example: http://localhost:8000/_site/#/myindex/?host=my-es-host.com:9200&refreshInterval=500
1 parent 977df54 commit 6c048a3

File tree

1 file changed

+74
-64
lines changed

1 file changed

+74
-64
lines changed

_site/js/app.js

Lines changed: 74 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
$(document).ready(function () {
22
(function($) {
33

4-
4+
55

66
var sort_by = function(field, reverse, primer){
77
var key = function (x) {return primer ? primer(x[field]) : x[field]};
88
return function (a,b) {
99
var A = key(a), B = key(b);
10-
return (A < B ? -1 : (A > B ? 1 : 0)) * [1,-1][+!!reverse];
10+
return (A < B ? -1 : (A > B ? 1 : 0)) * [1,-1][+!!reverse];
1111
}
1212
}
1313

@@ -25,19 +25,28 @@ $(document).ready(function () {
2525
global.loaded = false;
2626
global.refreshInterval = 500;
2727

28-
28+
2929
var app = Sammy("body", function() {
30-
30+
3131
this.use('Handlebars', 'hb');
3232

3333
////////////////////////////////////////
3434
this.helpers({
35-
35+
3636
initPage: function() {
37-
var context = this;
38-
37+
var context = this,
38+
acceptedParams = ['host', 'refreshInterval'];
39+
40+
$.each(acceptedParams, function(index, key) {
41+
var value = context.params[key];
42+
if (value) {
43+
global[key] = value;
44+
$('#' + key).val(value);
45+
}
46+
});
47+
3948
clearTimeout(global.pollID);
40-
49+
4150
if (global.loaded == false) {
4251
context.loadIndices();
4352
context.jq_pauseButton();
@@ -47,7 +56,7 @@ $(document).ready(function () {
4756
global.loaded = true;
4857
}
4958
},
50-
59+
5160
jq_pauseButton: function() {
5261
$("#pause").click(function(e) {
5362
if($(this).hasClass('btn-danger') == true) {
@@ -70,17 +79,17 @@ $(document).ready(function () {
7079
context.loadIndices();
7180
});
7281
},
73-
82+
7483
jq_refreshInterval: function() {
7584
$("#changeRefresh").click(function(e) {
7685
global.refreshInterval = $("#refreshInterval").val();
7786
});
7887
},
79-
88+
8089
loadIndices: function() {
81-
90+
8291
var context = this;
83-
92+
8493
var loadOptions = {type: 'get', dataType: 'json'};
8594
var stateOptions = "?filter_metadata=true&filter_blocks=true";
8695
context.load("//" + global.host + "/_cluster/state" + stateOptions, loadOptions)
@@ -91,136 +100,137 @@ $(document).ready(function () {
91100
$.each(state.routing_table.indices, function (index, v) {
92101
context.indices.push(index.toString());
93102
});
94-
95-
return context;
103+
104+
return context;
96105
})
97106
.render(global.indicesTemplate)
98107
.replace("#indices");
99108
},
100-
101-
109+
110+
102111
poll: function(index) {
103-
112+
104113
//Kill caching for all subsequent caching requests
105-
$.ajaxSetup ({
106-
cache: false
107-
});
108-
114+
$.ajaxSetup ({
115+
cache: false
116+
});
117+
109118
var formattedIndex = index;
110-
119+
111120
if (typeof index === 'undefined') {
112121
formattedIndex = "/";
113122
} else {
114123
formattedIndex += "/";
115124
}
116-
117-
var context = this;
118-
125+
126+
var context = this;
127+
119128
global.pollID = setTimeout(function(){
120-
129+
121130
if (global.pause == true) {
122131
context.poll(index);
123132
return;
124133
}
125-
134+
126135
//console.log("Poll: " + index);
127136
$.getJSON("//" + global.host + "/" + formattedIndex + "_segments/", function(data) {
128137
var segments = {};
129138

130139
$.each(data.indices[index].shards, function (shardKey, shardValue) {
131140
$.each(shardValue, function(shardKeyPR, shardValuePR) {
132-
141+
133142
var divId = "node_" + shardValuePR.routing.node + "_" + shardKey;
134-
143+
135144
if (typeof segments[divId] === 'undefined')
136145
segments[divId] = [];
137-
146+
138147
segments[divId].push(['Segment ID', 'Fully Synced', 'Committed', 'Uncommitted', 'Deleted Docs']);
139148
// flushed
140149
$.each(shardValuePR.segments, function (k,v) {
141-
150+
142151
//bit of math to normalize our values, since Google Charts doesn't do stacked log scales.
143152
var total = v.num_docs + v.deleted_docs;
144153
var deleted = 1 + log10(total) - log10(v.num_docs);
145-
154+
146155
if (deleted == 1)
147156
deleted = 0;
148157
else if (!isFinite(deleted))
149158
deleted = 0;
150-
159+
151160
//artificially boost num_docs by one, so you can see very small segments
152161
v.num_docs += 1;
153-
162+
154163
//fully committed/flushed and in memory
155164
if (v.search === true && v.committed === true)
156165
segments[divId].push([k, v.num_docs, 0, 0, deleted]);
157-
166+
158167
//Lucene Committed to disk
159168
else if (v.search === false && v.committed === true) {
160169
segments[divId].push([k, 0, v.num_docs, 0, deleted]);
161170
//console.log('v.search === true && v.committed === false');
162171
}
163-
172+
164173
//Resident in NRT IndexReader (in memory), not Lucene Committed yet
165174
else if (v.search === true && v.committed === false){
166175
segments[divId].push([k, 0, 0, v.num_docs, deleted]);
167176
//console.log(v);
168177
}
169-
178+
170179
//After reading the ES source, this option does not appear possible
171180
//else if (v.search === false && v.committed === false)
172181
// segments[divId].push([k, 0, 0, 0, v.num_docs, deleted]);
173-
182+
174183
});
175184
});
176185
});
177186

178187
if (segments !== {}) {
179188
$.each(segments, function (divId, segmentList) {
180189
segmentList = segmentList.sort(function(a,b) {
181-
//we can do this because only one of these values will be >0 due to
190+
//we can do this because only one of these values will be >0 due to
182191
//the quirky need to abuse Google Charts for multicolor
183192
var docsA = a[1] + a[2] + a[3];
184193
var docsB = b[1] + b[2] + b[3];
185194
return parseInt(docsB) - parseInt(docsA);
186195
});
187-
196+
188197
global.graphs[divId].setData(segmentList);
189198
global.graphs[divId].drawChart();
190-
191-
199+
200+
192201
});
193202
}
194203

195204

196205
})
197206
.always(function() { context.poll(index); });
198207
},global.refreshInterval);
199-
200-
},
208+
209+
},
201210
});
202211
///////////////////////////////////////////// End Helpers
203212

204-
213+
205214
this.get('#/', function(context) {
215+
206216
context.initPage();
207-
208-
217+
218+
209219
context.render(global.homeTemplate)
210220
.replace("#content")
211221
});
212-
222+
213223
this.get('#/:index/', function(context) {
214-
224+
215225
context.initPage();
216-
226+
217227
var targetIndex = context.params.index;
218-
228+
219229
var loadOptions = {type: 'get', dataType: 'json'};
220230
var stateOptions = "?filter_metadata=true&filter_blocks=true";
221231
context.load("//" + global.host + "/_cluster/state" + stateOptions, loadOptions)
222232
.then(function(state) {
223-
233+
224234
context.cluster_name = state.cluster_name;
225235
context.master_node = state.master_node;
226236

@@ -230,22 +240,22 @@ $(document).ready(function () {
230240
if (typeof context.nodes[pr.node] === 'undefined') {
231241
context.nodes[pr.node] = new Array();
232242
}
233-
243+
234244
//css ids can't start with numbers, prepend with "node"
235245
context.nodes[pr.node].push( {id: "node_" + pr.node + "_" + shardId,
236246
node: pr.node,
237247
index: pr.index,
238248
primary: pr.primary} );
239249

240250
});
241-
242-
243-
244-
251+
252+
253+
254+
245255
});
246256

247-
248-
return context;
257+
258+
return context;
249259
})
250260
.render(global.graphTemplate)
251261
.replace("#content")
@@ -256,14 +266,14 @@ $(document).ready(function () {
256266
global.graphs[div.id].init(div.id);
257267
});
258268
});
259-
269+
260270
context.poll(targetIndex);
261271
});
262272
});
263-
273+
264274
});
265-
275+
266276
app.run('#/');
267-
277+
268278
})(jQuery);
269279
});

0 commit comments

Comments
 (0)