private Double fetchInstancesOnlineRatio ( ObjectId collectorItemId ) { int totalInstances = 0 , totalInstancesOnline = 0 ; Double instancesOnlineScore = null ; List < EnvironmentStatus > statuses = environmentStatusRepository . findByCollectorItemId ( collectorItemId ) ; if ( null == statuses || statuses . isEmpty ( ) ) { return null ; } for ( EnvironmentStatus environmentStatus : statuses ) { totalInstances ++ ; if ( environmentStatus . isOnline ( ) ) { totalInstancesOnline ++ ; } } instancesOnlineScore = ( ( totalInstancesOnline * 100 ) / ( double ) totalInstances ) ; LOGGER . info ( "totalInstances " + totalInstances + " totalInstancesOnline " + totalInstancesOnline + " instancesOnlineScore " + instancesOnlineScore ) ; return instancesOnlineScore ; }
Calculate percentage of instances online