def add_worker(): if 'authorized' in session and session[ 'authorized'] is True and 'type' in session and session[ 'type'] == 'admin': ScalingTool.spawn_one_instance() dbm = DataBaseManager() uth, dth, ex_ratio, s_ratio, mode = dbm.get_scaling_settings() mode = 'manual' dbm.scaling(str(int(uth)), str(int(dth)), str(int(ex_ratio)), str(int(s_ratio)), mode) return redirect(url_for('admin_main_landing')) return redirect(url_for('index'))
def admin_main_landing(): if 'authorized' in session and session[ 'authorized'] is True and 'type' in session and session[ 'type'] == 'admin': cpu_stats, instances, _x = ScalingTool.get_instances_load() instance_list = [dict['InstanceId'] for dict in instances] length = len(cpu_stats) dbm = DataBaseManager() uth, dth, ex_ratio, s_ratio, mode = dbm.get_scaling_settings() return render_template('adminhome.html', length=length, instance_list=instance_list, cpu_stats=cpu_stats, ex_ratio=ex_ratio, s_ratio=s_ratio, uth=uth, dth=dth, mode=mode) return redirect(url_for('index'))
import time from app.tools.scalingTools import ScalingTool from app.tools.dbTools import DataBaseManager print('Scaling application has started...') while True: time.sleep(10) # Get database scaling settings dbm = DataBaseManager(False) instance_start_load, instance_termination_load, up_scale_factor, down_scale_factor, mode = dbm.get_scaling_settings() if mode != 'auto': continue # Get number of instances in service on load balancer total_running_instances = ScalingTool.get_number_of_in_service_instances_in_load_balancer() # Read load balancer average instance loads avg_load = ScalingTool.get_load_balancer_instances_avg_load() print('Avg. CPU load = {}'.format(avg_load)) # Should instances be terminated? if avg_load < instance_termination_load: n_instances_to_terminate = total_running_instances - total_running_instances // down_scale_factor expected_n_instances = total_running_instances - n_instances_to_terminate if expected_n_instances <= 1: print('Expected number of instances limited to 1') n_instances_to_terminate = total_running_instances - 1