1
1
$ ( document ) . ready ( function ( ) {
2
2
( function ( $ ) {
3
3
4
-
4
+
5
5
6
6
var sort_by = function ( field , reverse , primer ) {
7
7
var key = function ( x ) { return primer ? primer ( x [ field ] ) : x [ field ] } ;
8
8
return function ( a , b ) {
9
9
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 ] ;
11
11
}
12
12
}
13
13
@@ -25,19 +25,28 @@ $(document).ready(function () {
25
25
global . loaded = false ;
26
26
global . refreshInterval = 500 ;
27
27
28
-
28
+
29
29
var app = Sammy ( "body" , function ( ) {
30
-
30
+
31
31
this . use ( 'Handlebars' , 'hb' ) ;
32
32
33
33
////////////////////////////////////////
34
34
this . helpers ( {
35
-
35
+
36
36
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
+
39
48
clearTimeout ( global . pollID ) ;
40
-
49
+
41
50
if ( global . loaded == false ) {
42
51
context . loadIndices ( ) ;
43
52
context . jq_pauseButton ( ) ;
@@ -47,7 +56,7 @@ $(document).ready(function () {
47
56
global . loaded = true ;
48
57
}
49
58
} ,
50
-
59
+
51
60
jq_pauseButton : function ( ) {
52
61
$ ( "#pause" ) . click ( function ( e ) {
53
62
if ( $ ( this ) . hasClass ( 'btn-danger' ) == true ) {
@@ -70,17 +79,17 @@ $(document).ready(function () {
70
79
context . loadIndices ( ) ;
71
80
} ) ;
72
81
} ,
73
-
82
+
74
83
jq_refreshInterval : function ( ) {
75
84
$ ( "#changeRefresh" ) . click ( function ( e ) {
76
85
global . refreshInterval = $ ( "#refreshInterval" ) . val ( ) ;
77
86
} ) ;
78
87
} ,
79
-
88
+
80
89
loadIndices : function ( ) {
81
-
90
+
82
91
var context = this ;
83
-
92
+
84
93
var loadOptions = { type : 'get' , dataType : 'json' } ;
85
94
var stateOptions = "?filter_metadata=true&filter_blocks=true" ;
86
95
context . load ( "//" + global . host + "/_cluster/state" + stateOptions , loadOptions )
@@ -91,136 +100,137 @@ $(document).ready(function () {
91
100
$ . each ( state . routing_table . indices , function ( index , v ) {
92
101
context . indices . push ( index . toString ( ) ) ;
93
102
} ) ;
94
-
95
- return context ;
103
+
104
+ return context ;
96
105
} )
97
106
. render ( global . indicesTemplate )
98
107
. replace ( "#indices" ) ;
99
108
} ,
100
-
101
-
109
+
110
+
102
111
poll : function ( index ) {
103
-
112
+
104
113
//Kill caching for all subsequent caching requests
105
- $ . ajaxSetup ( {
106
- cache : false
107
- } ) ;
108
-
114
+ $ . ajaxSetup ( {
115
+ cache : false
116
+ } ) ;
117
+
109
118
var formattedIndex = index ;
110
-
119
+
111
120
if ( typeof index === 'undefined' ) {
112
121
formattedIndex = "/" ;
113
122
} else {
114
123
formattedIndex += "/" ;
115
124
}
116
-
117
- var context = this ;
118
-
125
+
126
+ var context = this ;
127
+
119
128
global . pollID = setTimeout ( function ( ) {
120
-
129
+
121
130
if ( global . pause == true ) {
122
131
context . poll ( index ) ;
123
132
return ;
124
133
}
125
-
134
+
126
135
//console.log("Poll: " + index);
127
136
$ . getJSON ( "//" + global . host + "/" + formattedIndex + "_segments/" , function ( data ) {
128
137
var segments = { } ;
129
138
130
139
$ . each ( data . indices [ index ] . shards , function ( shardKey , shardValue ) {
131
140
$ . each ( shardValue , function ( shardKeyPR , shardValuePR ) {
132
-
141
+
133
142
var divId = "node_" + shardValuePR . routing . node + "_" + shardKey ;
134
-
143
+
135
144
if ( typeof segments [ divId ] === 'undefined' )
136
145
segments [ divId ] = [ ] ;
137
-
146
+
138
147
segments [ divId ] . push ( [ 'Segment ID' , 'Fully Synced' , 'Committed' , 'Uncommitted' , 'Deleted Docs' ] ) ;
139
148
// flushed
140
149
$ . each ( shardValuePR . segments , function ( k , v ) {
141
-
150
+
142
151
//bit of math to normalize our values, since Google Charts doesn't do stacked log scales.
143
152
var total = v . num_docs + v . deleted_docs ;
144
153
var deleted = 1 + log10 ( total ) - log10 ( v . num_docs ) ;
145
-
154
+
146
155
if ( deleted == 1 )
147
156
deleted = 0 ;
148
157
else if ( ! isFinite ( deleted ) )
149
158
deleted = 0 ;
150
-
159
+
151
160
//artificially boost num_docs by one, so you can see very small segments
152
161
v . num_docs += 1 ;
153
-
162
+
154
163
//fully committed/flushed and in memory
155
164
if ( v . search === true && v . committed === true )
156
165
segments [ divId ] . push ( [ k , v . num_docs , 0 , 0 , deleted ] ) ;
157
-
166
+
158
167
//Lucene Committed to disk
159
168
else if ( v . search === false && v . committed === true ) {
160
169
segments [ divId ] . push ( [ k , 0 , v . num_docs , 0 , deleted ] ) ;
161
170
//console.log('v.search === true && v.committed === false');
162
171
}
163
-
172
+
164
173
//Resident in NRT IndexReader (in memory), not Lucene Committed yet
165
174
else if ( v . search === true && v . committed === false ) {
166
175
segments [ divId ] . push ( [ k , 0 , 0 , v . num_docs , deleted ] ) ;
167
176
//console.log(v);
168
177
}
169
-
178
+
170
179
//After reading the ES source, this option does not appear possible
171
180
//else if (v.search === false && v.committed === false)
172
181
// segments[divId].push([k, 0, 0, 0, v.num_docs, deleted]);
173
-
182
+
174
183
} ) ;
175
184
} ) ;
176
185
} ) ;
177
186
178
187
if ( segments !== { } ) {
179
188
$ . each ( segments , function ( divId , segmentList ) {
180
189
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
182
191
//the quirky need to abuse Google Charts for multicolor
183
192
var docsA = a [ 1 ] + a [ 2 ] + a [ 3 ] ;
184
193
var docsB = b [ 1 ] + b [ 2 ] + b [ 3 ] ;
185
194
return parseInt ( docsB ) - parseInt ( docsA ) ;
186
195
} ) ;
187
-
196
+
188
197
global . graphs [ divId ] . setData ( segmentList ) ;
189
198
global . graphs [ divId ] . drawChart ( ) ;
190
-
191
-
199
+
200
+
192
201
} ) ;
193
202
}
194
203
195
204
196
205
} )
197
206
. always ( function ( ) { context . poll ( index ) ; } ) ;
198
207
} , global . refreshInterval ) ;
199
-
200
- } ,
208
+
209
+ } ,
201
210
} ) ;
202
211
///////////////////////////////////////////// End Helpers
203
212
204
-
213
+
205
214
this . get ( '#/' , function ( context ) {
215
+
206
216
context . initPage ( ) ;
207
-
208
-
217
+
218
+
209
219
context . render ( global . homeTemplate )
210
220
. replace ( "#content" )
211
221
} ) ;
212
-
222
+
213
223
this . get ( '#/:index/' , function ( context ) {
214
-
224
+
215
225
context . initPage ( ) ;
216
-
226
+
217
227
var targetIndex = context . params . index ;
218
-
228
+
219
229
var loadOptions = { type : 'get' , dataType : 'json' } ;
220
230
var stateOptions = "?filter_metadata=true&filter_blocks=true" ;
221
231
context . load ( "//" + global . host + "/_cluster/state" + stateOptions , loadOptions )
222
232
. then ( function ( state ) {
223
-
233
+
224
234
context . cluster_name = state . cluster_name ;
225
235
context . master_node = state . master_node ;
226
236
@@ -230,22 +240,22 @@ $(document).ready(function () {
230
240
if ( typeof context . nodes [ pr . node ] === 'undefined' ) {
231
241
context . nodes [ pr . node ] = new Array ( ) ;
232
242
}
233
-
243
+
234
244
//css ids can't start with numbers, prepend with "node"
235
245
context . nodes [ pr . node ] . push ( { id : "node_" + pr . node + "_" + shardId ,
236
246
node : pr . node ,
237
247
index : pr . index ,
238
248
primary : pr . primary } ) ;
239
249
240
250
} ) ;
241
-
242
-
243
-
244
-
251
+
252
+
253
+
254
+
245
255
} ) ;
246
256
247
-
248
- return context ;
257
+
258
+ return context ;
249
259
} )
250
260
. render ( global . graphTemplate )
251
261
. replace ( "#content" )
@@ -256,14 +266,14 @@ $(document).ready(function () {
256
266
global . graphs [ div . id ] . init ( div . id ) ;
257
267
} ) ;
258
268
} ) ;
259
-
269
+
260
270
context . poll ( targetIndex ) ;
261
271
} ) ;
262
272
} ) ;
263
-
273
+
264
274
} ) ;
265
-
275
+
266
276
app . run ( '#/' ) ;
267
-
277
+
268
278
} ) ( jQuery ) ;
269
279
} ) ;
0 commit comments