2015-02-23 00:42:36 -05:00
/ *
Licensed to the Apache Software Foundation ( ASF ) under one or more
contributor license agreements . See the NOTICE file distributed with
this work for additional information regarding copyright ownership .
The ASF licenses this file to You under the Apache License , Version 2.0
( the "License" ) ; you may not use this file except in compliance with
the License . You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
solrAdminApp . controller ( 'IndexController' , [ '$scope' , 'System' , 'Cores' , function ( $scope , System , Cores ) {
2015-07-30 16:00:59 -04:00
$scope . resetMenu ( "index" , true ) ;
2015-02-23 00:42:36 -05:00
$scope . reload = function ( ) {
System . get ( function ( data ) {
$scope . system = data ;
// load average
load _average = ( data . system . uptime || '' ) . match ( /load averages?: (\d+[.,]\d\d),? (\d+[.,]\d\d),? (\d+[.,]\d\d)/ ) ;
for ( var i = 0 ; i < 2 ; i ++ ) {
load _average [ i ] = load _average [ i ] . replace ( "," , "." ) ; // for European users
}
$scope . load _average = load _average . slice ( 1 ) ;
// physical memory
var memoryMax = parse _memory _value ( data . system . totalPhysicalMemorySize ) ;
$scope . memoryTotal = parse _memory _value ( data . system . totalPhysicalMemorySize - data . system . freePhysicalMemorySize ) ;
$scope . memoryPercentage = ( $scope . memoryTotal / memoryMax * 100 ) . toFixed ( 1 ) + "%" ;
$scope . memoryMax = pretty _print _bytes ( memoryMax ) ;
$scope . memoryTotalDisplay = pretty _print _bytes ( $scope . memoryTotal ) ;
// swap space
var swapMax = parse _memory _value ( data . system . totalSwapSpaceSize ) ;
$scope . swapTotal = parse _memory _value ( data . system . totalSwapSpaceSize - data . system . freeSwapSpaceSize ) ;
$scope . swapPercentage = ( $scope . swapTotal / swapMax * 100 ) . toFixed ( 1 ) + "%" ;
$scope . swapMax = pretty _print _bytes ( swapMax ) ;
$scope . swapTotalDisplay = pretty _print _bytes ( $scope . swapTotal ) ;
// file handles
$scope . fileDescriptorPercentage = ( data . system . openFileDescriptorCount / data . system . maxFileDescriptorCount * 100 ) . toFixed ( 1 ) + "%" ;
// java memory
var javaMemoryMax = parse _memory _value ( data . jvm . memory . raw . max || data . jvm . memory . max ) ;
$scope . javaMemoryTotal = parse _memory _value ( data . jvm . memory . raw . total || data . jvm . memory . total ) ;
$scope . javaMemoryUsed = parse _memory _value ( data . jvm . memory . raw . used || data . jvm . memory . used ) ;
$scope . javaMemoryTotalPercentage = ( $scope . javaMemoryTotal / javaMemoryMax * 100 ) . toFixed ( 1 ) + "%" ;
$scope . javaMemoryUsedPercentage = ( $scope . javaMemoryUsed / $scope . javaMemoryTotal * 100 ) . toFixed ( 1 ) + "%" ;
$scope . javaMemoryPercentage = ( $scope . javaMemoryUsed / javaMemoryMax * 100 ) . toFixed ( 1 ) + "%" ;
$scope . javaMemoryTotalDisplay = pretty _print _bytes ( $scope . javaMemoryTotal ) ;
$scope . javaMemoryUsedDisplay = pretty _print _bytes ( $scope . javaMemoryUsed ) ; // @todo These should really be an AngularJS Filter: {{ javaMemoryUsed | bytes }}
$scope . javaMemoryMax = pretty _print _bytes ( javaMemoryMax ) ;
// no info bar:
$scope . noInfo = ! (
data . system . totalPhysicalMemorySize && data . system . freePhysicalMemorySize &&
data . system . totalSwapSpaceSize && data . system . freeSwapSpaceSize &&
data . system . openFileDescriptorCount && data . system . maxFileDescriptorCount ) ;
// command line args:
$scope . commandLineArgs = data . jvm . jmx . commandLineArgs . sort ( ) ;
} ) ;
} ;
$scope . reload ( ) ;
} ] ) ;
var parse _memory _value = function ( value ) {
if ( value !== Number ( value ) )
{
var units = 'BKMGTPEZY' ;
var match = value . match ( /^(\d+([,\.]\d+)?) (\w).*$/ ) ;
var value = parseFloat ( match [ 1 ] ) * Math . pow ( 1024 , units . indexOf ( match [ 3 ] . toUpperCase ( ) ) ) ;
}
return value ;
} ;
var pretty _print _bytes = function ( byte _value ) {
var unit = null ;
byte _value /= 1024 ;
byte _value /= 1024 ;
unit = 'MB' ;
if ( 1024 <= byte _value ) {
byte _value /= 1024 ;
unit = 'GB' ;
}
return byte _value . toFixed ( 2 ) + ' ' + unit ;
} ;