[7588] | 1 | /* |
---|
| 2 | Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 3 | contributor license agreements. See the NOTICE file distributed with |
---|
| 4 | this work for additional information regarding copyright ownership. |
---|
| 5 | The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 6 | (the "License"); you may not use this file except in compliance with |
---|
| 7 | the License. You may obtain a copy of the License at |
---|
| 8 | |
---|
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | |
---|
| 11 | Unless required by applicable law or agreed to in writing, software |
---|
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 14 | See the License for the specific language governing permissions and |
---|
| 15 | limitations under the License. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | var parse_memory_value = function( value ) |
---|
| 19 | { |
---|
| 20 | if( value !== Number( value ) ) |
---|
| 21 | { |
---|
| 22 | var units = 'BKMGTPEZY'; |
---|
| 23 | var match = value.match( /^(\d+([,\.]\d+)?) (\w)\w?$/ ); |
---|
| 24 | var value = parseFloat( match[1] ) * Math.pow( 1024, units.indexOf( match[3].toUpperCase() ) ); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | return value; |
---|
| 28 | }; |
---|
| 29 | |
---|
| 30 | var generate_bar = function( bar_container, bar_data, convert_label_values ) |
---|
| 31 | { |
---|
| 32 | bar_holder = $( '.bar-holder', bar_container ); |
---|
| 33 | |
---|
| 34 | var bar_level = 1; |
---|
| 35 | var max_width = Math.round( $( '.bar-max', bar_holder ).width() ); |
---|
| 36 | $( '.bar-max.val', bar_holder ).text( bar_data['max'] ); |
---|
| 37 | |
---|
| 38 | bar_level++; |
---|
| 39 | var total_width = Math.round( ( bar_data['total'] * max_width ) / bar_data['max'] ); |
---|
| 40 | $( '.bar-total.bar', bar_holder ).width( Math.max( total_width, 1 ) ); |
---|
| 41 | $( '.bar-total.val', bar_holder ).text( bar_data['total'] ); |
---|
| 42 | |
---|
| 43 | if( bar_data['used'] ) |
---|
| 44 | { |
---|
| 45 | bar_level++; |
---|
| 46 | var used_width = Math.round( ( bar_data['used'] * max_width ) / bar_data['max'] ); |
---|
| 47 | $( '.bar-used.bar', bar_holder ).width( Math.min( used_width, total_width - 1 ) ); |
---|
| 48 | $( '.bar-used.val', bar_holder ).text( bar_data['used'] ); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | bar_holder |
---|
| 52 | .addClass( 'bar-lvl-' + bar_level ); |
---|
| 53 | |
---|
| 54 | var percentage = ( ( ( bar_data['used'] || bar_data['total'] ) / bar_data['max'] ) * 100 ).toFixed(1); |
---|
| 55 | |
---|
| 56 | var hl = $( '[data-desc="' + bar_container.attr( 'id' ) + '"]' ); |
---|
| 57 | |
---|
| 58 | $( '.bar-desc', hl ) |
---|
| 59 | .remove(); |
---|
| 60 | |
---|
| 61 | hl |
---|
| 62 | .append( ' <small class="bar-desc">' + percentage + '%</small>' ); |
---|
| 63 | |
---|
| 64 | if( !!convert_label_values ) |
---|
| 65 | { |
---|
| 66 | $( '.val', bar_holder ) |
---|
| 67 | .each |
---|
| 68 | ( |
---|
| 69 | function() |
---|
| 70 | { |
---|
| 71 | var self = $( this ); |
---|
| 72 | |
---|
| 73 | var unit = null; |
---|
| 74 | var byte_value = parseInt( self.html() ); |
---|
| 75 | |
---|
| 76 | self |
---|
| 77 | .attr( 'title', 'raw: ' + byte_value + ' B' ); |
---|
| 78 | |
---|
| 79 | byte_value /= 1024; |
---|
| 80 | byte_value /= 1024; |
---|
| 81 | unit = 'MB'; |
---|
| 82 | |
---|
| 83 | if( 1024 <= byte_value ) |
---|
| 84 | { |
---|
| 85 | byte_value /= 1024; |
---|
| 86 | unit = 'GB'; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | byte_value = byte_value.toFixed( 2 ) + ' ' + unit; |
---|
| 90 | |
---|
| 91 | self |
---|
| 92 | .text( byte_value ); |
---|
| 93 | } |
---|
| 94 | ); |
---|
| 95 | } |
---|
| 96 | }; |
---|
| 97 | |
---|
| 98 | var system_info = function( element, system_data ) |
---|
| 99 | { |
---|
| 100 | // -- usage |
---|
| 101 | |
---|
| 102 | var load_average = ( system_data['system']['uptime'] || '' ).match( /load average: (.+)/ ); |
---|
| 103 | if( load_average && load_average[1] ) |
---|
| 104 | { |
---|
| 105 | var hl = $( '#system h2', element ); |
---|
| 106 | |
---|
| 107 | $( '.bar-desc', hl ) |
---|
| 108 | .remove(); |
---|
| 109 | |
---|
| 110 | hl |
---|
| 111 | .append( ' <small class="bar-desc">' + load_average[1].split( ', ' ).join( ' ' ).esc() + '</small>' ); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | // -- physical-memory-bar |
---|
| 115 | |
---|
| 116 | var bar_holder = $( '#physical-memory-bar', element ); |
---|
| 117 | if( !system_data['system']['totalPhysicalMemorySize'] ) |
---|
| 118 | { |
---|
| 119 | bar_holder.hide(); |
---|
| 120 | } |
---|
| 121 | else |
---|
| 122 | { |
---|
| 123 | bar_holder.show(); |
---|
| 124 | |
---|
| 125 | var bar_data = { |
---|
| 126 | 'max' : parse_memory_value( system_data['system']['totalPhysicalMemorySize'] ), |
---|
| 127 | 'total' : parse_memory_value( system_data['system']['totalPhysicalMemorySize'] - system_data['system']['freePhysicalMemorySize'] ) |
---|
| 128 | }; |
---|
| 129 | |
---|
| 130 | generate_bar( bar_holder, bar_data, true ); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | // -- swap-space-bar |
---|
| 134 | |
---|
| 135 | var bar_holder = $( '#swap-space-bar', element ); |
---|
| 136 | if( !system_data['system']['totalSwapSpaceSize'] ) |
---|
| 137 | { |
---|
| 138 | bar_holder.hide(); |
---|
| 139 | } |
---|
| 140 | else |
---|
| 141 | { |
---|
| 142 | bar_holder.show(); |
---|
| 143 | |
---|
| 144 | var bar_data = { |
---|
| 145 | 'max' : parse_memory_value( system_data['system']['totalSwapSpaceSize'] ), |
---|
| 146 | 'total' : parse_memory_value( system_data['system']['totalSwapSpaceSize'] - system_data['system']['freeSwapSpaceSize'] ) |
---|
| 147 | }; |
---|
| 148 | |
---|
| 149 | generate_bar( bar_holder, bar_data, true ); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | // -- swap-space-bar |
---|
| 153 | |
---|
| 154 | var bar_holder = $( '#file-descriptor-bar', element ); |
---|
| 155 | if( !system_data['system']['maxFileDescriptorCount'] ) |
---|
| 156 | { |
---|
| 157 | bar_holder.hide(); |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | { |
---|
| 161 | bar_holder.show(); |
---|
| 162 | |
---|
| 163 | var bar_data = { |
---|
| 164 | 'max' : parse_memory_value( system_data['system']['maxFileDescriptorCount'] ), |
---|
| 165 | 'total' : parse_memory_value( system_data['system']['openFileDescriptorCount'] ) |
---|
| 166 | }; |
---|
| 167 | |
---|
| 168 | generate_bar( bar_holder, bar_data ); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | 0 === $( '#system div[id$="-bar"]:visible', element ).size() |
---|
| 172 | ? $( '#system .no-info', element ).show() |
---|
| 173 | : $( '#system .no-info', element ).hide(); |
---|
| 174 | |
---|
| 175 | // -- memory-bar |
---|
| 176 | |
---|
| 177 | var jvm_memory = $.extend |
---|
| 178 | ( |
---|
| 179 | { |
---|
| 180 | 'free' : null, |
---|
| 181 | 'total' : null, |
---|
| 182 | 'max' : null, |
---|
| 183 | 'used' : null, |
---|
| 184 | 'raw' : { |
---|
| 185 | 'free' : null, |
---|
| 186 | 'total' : null, |
---|
| 187 | 'max' : null, |
---|
| 188 | 'used' : null, |
---|
| 189 | 'used%' : null |
---|
| 190 | } |
---|
| 191 | }, |
---|
| 192 | system_data['jvm']['memory'] |
---|
| 193 | ); |
---|
| 194 | |
---|
| 195 | var bar_holder = $( '#jvm-memory-bar', element ); |
---|
| 196 | var bar_data = { |
---|
| 197 | 'max' : parse_memory_value( jvm_memory['raw']['max'] || jvm_memory['max'] ), |
---|
| 198 | 'total' : parse_memory_value( jvm_memory['raw']['total'] || jvm_memory['total'] ), |
---|
| 199 | 'used' : parse_memory_value( jvm_memory['raw']['used'] || jvm_memory['used'] ) |
---|
| 200 | }; |
---|
| 201 | |
---|
| 202 | generate_bar( bar_holder, bar_data, true ); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | // #/ |
---|
| 206 | sammy.get |
---|
| 207 | ( |
---|
| 208 | /^#\/$/, |
---|
| 209 | function( context ) |
---|
| 210 | { |
---|
| 211 | var content_element = $( '#content' ); |
---|
| 212 | |
---|
| 213 | $( '#menu-wrapper #index' ) |
---|
| 214 | .addClass( 'active' ); |
---|
| 215 | |
---|
| 216 | content_element |
---|
| 217 | .html( '<div id="index"></div>' ); |
---|
| 218 | |
---|
| 219 | $.ajax |
---|
| 220 | ( |
---|
| 221 | { |
---|
| 222 | url : 'tpl/index.html', |
---|
| 223 | context : $( '#index', content_element ), |
---|
| 224 | beforeSend : function( arr, form, options ) |
---|
| 225 | { |
---|
| 226 | }, |
---|
| 227 | success : function( template ) |
---|
| 228 | { |
---|
| 229 | var self = this; |
---|
| 230 | |
---|
| 231 | this |
---|
| 232 | .html( template ); |
---|
| 233 | |
---|
| 234 | var data = { |
---|
| 235 | 'start_time' : app.dashboard_values['jvm']['jmx']['startTime'], |
---|
| 236 | 'host' : app.dashboard_values['core']['host'], |
---|
| 237 | 'dir_instance' : app.dashboard_values['core']['directory']['instance'], |
---|
| 238 | 'dir_data' : app.dashboard_values['core']['directory']['data'], |
---|
| 239 | 'dir_index' : app.dashboard_values['core']['directory']['index'], |
---|
| 240 | 'jvm_version' : app.dashboard_values['jvm']['name'] + ' (' + app.dashboard_values['jvm']['version'] + ')', |
---|
| 241 | 'processors' : app.dashboard_values['jvm']['processors'], |
---|
| 242 | 'solr_spec_version' : app.dashboard_values['lucene']['solr-spec-version'] || '-', |
---|
| 243 | 'solr_impl_version' : app.dashboard_values['lucene']['solr-impl-version'] || '-', |
---|
| 244 | 'lucene_spec_version' : app.dashboard_values['lucene']['lucene-spec-version'] || '-', |
---|
| 245 | 'lucene_impl_version' : app.dashboard_values['lucene']['lucene-impl-version'] || '-' |
---|
| 246 | }; |
---|
| 247 | |
---|
| 248 | if( app.dashboard_values['core']['directory']['cwd'] ) |
---|
| 249 | { |
---|
| 250 | data['dir_cwd'] = app.dashboard_values['core']['directory']['cwd']; |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | for( var key in data ) |
---|
| 254 | { |
---|
| 255 | var value_element = $( '.' + key + ' dd', this ); |
---|
| 256 | |
---|
| 257 | value_element |
---|
| 258 | .text( data[key].esc() ); |
---|
| 259 | |
---|
| 260 | value_element.closest( 'li' ) |
---|
| 261 | .show(); |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | var commandLineArgs = app.dashboard_values['jvm']['jmx']['commandLineArgs']; |
---|
| 265 | if( 0 !== commandLineArgs.length ) |
---|
| 266 | { |
---|
| 267 | var cmd_arg_element = $( '.command_line_args dt', this ); |
---|
| 268 | var cmd_arg_key_element = $( '.command_line_args dt', this ); |
---|
| 269 | var cmd_arg_element = $( '.command_line_args dd', this ); |
---|
| 270 | |
---|
| 271 | for( var key in commandLineArgs ) |
---|
| 272 | { |
---|
| 273 | cmd_arg_element = cmd_arg_element.clone(); |
---|
| 274 | cmd_arg_element.text( commandLineArgs[key] ); |
---|
| 275 | |
---|
| 276 | cmd_arg_key_element |
---|
| 277 | .after( cmd_arg_element ); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | cmd_arg_key_element.closest( 'li' ) |
---|
| 281 | .show(); |
---|
| 282 | |
---|
| 283 | $( '.command_line_args dd:last', this ) |
---|
| 284 | .remove(); |
---|
| 285 | |
---|
| 286 | $( '.command_line_args dd:odd', this ) |
---|
| 287 | .addClass( 'odd' ); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | $( '.timeago', this ) |
---|
| 291 | .timeago(); |
---|
| 292 | |
---|
| 293 | $( '.index-left .block li:visible:odd', this ) |
---|
| 294 | .addClass( 'odd' ); |
---|
| 295 | |
---|
| 296 | // -- system_info |
---|
| 297 | |
---|
| 298 | system_info( this, app.dashboard_values ); |
---|
| 299 | |
---|
| 300 | $( '#system a.reload', this ) |
---|
| 301 | .die( 'click' ) |
---|
| 302 | .live |
---|
| 303 | ( |
---|
| 304 | 'click', |
---|
| 305 | function( event ) |
---|
| 306 | { |
---|
| 307 | $.ajax |
---|
| 308 | ( |
---|
| 309 | { |
---|
| 310 | url : environment_basepath + '/admin/system?wt=json', |
---|
| 311 | dataType : 'json', |
---|
| 312 | context : this, |
---|
| 313 | beforeSend : function( arr, form, options ) |
---|
| 314 | { |
---|
| 315 | loader.show( this ); |
---|
| 316 | }, |
---|
| 317 | success : function( response ) |
---|
| 318 | { |
---|
| 319 | system_info( self, response ); |
---|
| 320 | }, |
---|
| 321 | error : function() |
---|
| 322 | { |
---|
| 323 | }, |
---|
| 324 | complete : function() |
---|
| 325 | { |
---|
| 326 | loader.hide( this ); |
---|
| 327 | } |
---|
| 328 | } |
---|
| 329 | ); |
---|
| 330 | |
---|
| 331 | return false; |
---|
| 332 | } |
---|
| 333 | ); |
---|
| 334 | }, |
---|
| 335 | error : function( xhr, text_status, error_thrown ) |
---|
| 336 | { |
---|
| 337 | }, |
---|
| 338 | complete : function( xhr, text_status ) |
---|
| 339 | { |
---|
| 340 | } |
---|
| 341 | } |
---|
| 342 | ); |
---|
| 343 | } |
---|
| 344 | ); |
---|