Beispiel #1
0
def _print_information_about_elb_and_instances(env_name):
    env_dict = elasticbeanstalk.get_environment_resources(env_name)
    instances = [instance['Id'] for instance in env_dict['EnvironmentResources']['Instances']]
    io.echo('  Running instances:', len(instances))

    load_balancers = env_dict['EnvironmentResources']['LoadBalancers']
    if load_balancers:
        load_balancer_name = load_balancers[0]['Name']
        if elb.is_classic_load_balancer(load_balancer_name):
            _print_elb_health_stats(load_balancer_name, instances)
        elif load_balancer_name:
            _print_elbv2_health_stats(load_balancer_name, instances)
Beispiel #2
0
    def _get_health_data(self):
        timestamp = datetime.now(tz.tzutc())
        env = elasticbeanstalk.get_environment(app_name=self.app_name,
                                               env_name=self.env_name)
        env_dict = elasticbeanstalk.get_environment_resources(self.env_name)
        env_dict = env_dict['EnvironmentResources']
        load_balancers = env_dict.get('LoadBalancers', None)
        if load_balancers and len(load_balancers) > 0:
            load_balancer_name = env_dict.get('LoadBalancers')[0].get('Name')
            instance_states = elb.get_health_of_instances(load_balancer_name)
        else:
            instance_states = []
        instance_ids = [i['Id'] for i in env_dict.get('Instances', [])]

        total_instances = len(instance_ids)
        total_in_service = len(
            [i for i in instance_states if i['State'] == 'InService'])
        env_data = {
            'EnvironmentName': env.name,
            'Color': env.health,
            'Status': env.status,
            'Total': total_instances,
            'InService': total_in_service,
            'Other': total_instances - total_in_service
        }

        data = {'environment': env_data, 'instances': []}

        # Get Instance Health
        for i in instance_states:
            instance = {
                'id': i['InstanceId'],
                'state': i['State'],
                'description': i['Description']
            }
            ec2_health = ec2.describe_instance(instance['id'])
            instance['health'] = ec2_health['State']['Name']
            data['instances'].append(instance)

        # Get Health for instances not in Load Balancer yet
        for i in instance_ids:
            instance = {'id': i}
            if i not in [x['InstanceId'] for x in instance_states]:
                instance['description'] = 'N/A (Not registered ' \
                                          'with Load Balancer)'
                instance['state'] = 'n/a'
                ec2_health = ec2.describe_instance(i)
                instance['health'] = ec2_health['State']['Name']
                data['instances'].append(instance)

        data['environment']['RefreshedAt'] = timestamp
        return data
Beispiel #3
0
    def _get_health_data(self):
        env_dict = elasticbeanstalk.get_environment_resources(self.env_name)
        environment_resources = env_dict['EnvironmentResources']
        instances_registered_with_elb = self.get_instance_states(environment_resources.get('LoadBalancers'))
        ids_of_all_instances = [instance['Id'] for instance in environment_resources.get('Instances', [])]
        all_instances = (
            self.get_instance_health(instances_registered_with_elb)
            +
            self.get_health_information_of_instance_not_associated_with_elb(
                ids_of_all_instances,
                instances_registered_with_elb
            )
        )

        return {
            'instances': all_instances,
            'environment': self.assemble_environment_data(ids_of_all_instances, instances_registered_with_elb)
        }
Beispiel #4
0
    def _get_health_data(self):
        env_dict = elasticbeanstalk.get_environment_resources(self.env_name)
        environment_resources = env_dict['EnvironmentResources']
        instances_registered_with_elb = self.get_instance_states(environment_resources.get('LoadBalancers'))
        ids_of_all_instances = [instance['Id'] for instance in environment_resources.get('Instances', [])]
        all_instances = (
            self.get_instance_health(instances_registered_with_elb)
            +
            self.get_health_information_of_instance_not_associated_with_elb(
                ids_of_all_instances,
                instances_registered_with_elb
            )
        )

        return {
            'instances': all_instances,
            'environment': self.assemble_environment_data(ids_of_all_instances, instances_registered_with_elb)
        }
Beispiel #5
0
def get_instance_ids(env_name):
    env = elasticbeanstalk.get_environment_resources(env_name)
    instances = [i['Id'] for i in env['EnvironmentResources']['Instances']]
    return instances