Beispiel #1
0
    def _get_sleep_time(refresh_time):
        if not refresh_time:
            return 2

        delta = utils.get_delta_from_now_and_datetime(refresh_time)

        countdown = 11 - delta.seconds
        LOG.debug(
            'health time={}. current={}. ({} seconds until next refresh)'.
            format(utils.get_local_time_as_string(refresh_time),
                   utils.get_local_time_as_string(datetime.now()), countdown))

        return max(0.5, min(countdown, 11))  # x in range [0.5, 11]
Beispiel #2
0
    def _get_sleep_time(refresh_time):
        if not refresh_time:
            return 2

        delta = utils.get_delta_from_now_and_datetime(refresh_time)

        countdown = 11 - delta.seconds
        LOG.debug(
            'health time={}. current={}. ({} seconds until next refresh)'.format(
                utils.get_local_time_as_string(refresh_time),
                utils.get_local_time_as_string(datetime.now()),
                countdown
            )
        )

        return max(0.5, min(countdown, 11))  # x in range [0.5, 11]
    def draw_banner_first_line(self, lines, data):
        status = data.get('HealthStatus', 'Unknown')
        refresh_time = data.get('RefreshedAt', None)
        if refresh_time is None:
            timestamp = '-'
            countdown = ' ( now )'
        else:
            timestamp = utils.get_local_time_as_string(refresh_time)
            delta = utils.get_delta_from_now_and_datetime(refresh_time)
            diff = 11 - delta.seconds
            if not self.refresh:
                countdown = ''
            elif self.frozen:
                countdown = ' (frozen +{})'.format(delta.seconds)
            elif diff < 0:
                countdown = ' ( now )'
            else:
                countdown = " ({} secs)".format(diff)
        env_name = data.get('EnvironmentName')
        pad_length = (term.width() - len(env_name) - len(timestamp) -
                      len(countdown) - 1)
        if lines > 2:
            banner = io.bold(' {env_name}{status}{time}{cd} ') \
                .format(env_name=env_name,
                        status=status.center(pad_length),
                        time=timestamp,
                        cd=countdown,
                        )
            if not self.mono:
                banner = io.on_color(data.get('Color', 'Grey'), banner)
            term.echo_line(banner)

            lines -= 1
        return lines
Beispiel #4
0
def collapse_instance_health_data(instances_health):
    instance_list = instances_health.get('InstanceHealthList', [])
    result = list()
    for i in instance_list:
        instance = dict()
        request_count = i.get('ApplicationMetrics', {}) \
            .get('RequestCount', 0)
        latency = i.get('ApplicationMetrics', {}).pop('Latency', {})
        instance.update(_format_latency_dict(latency, request_count))
        instance.update(i.get('ApplicationMetrics', {}).pop('StatusCodes', {}))
        instance.update(i.pop('ApplicationMetrics', {}))

        instance.update(i.get('System', {}).pop('CPUUtilization', {}))
        instance.update(i.pop('System', {}))
        instance.update(i)
        causes = instance.get('Causes', [])
        cause = causes[0] if causes else ''
        instance['Cause'] = cause

        instance['InstanceType'] = i.get('InstanceType')
        if i.get('AvailabilityZone'):
            try:
                instance['AvailabilityZone'] = i.get(
                    'AvailabilityZone').rsplit('-', 1)[-1]
            except:
                instance['AvailabilityZone'] = i.get('AvailabilityZone')
        if i.get('Deployment'):
            instance['TimeSinceDeployment'] = format_time_since(
                i.get('Deployment').get('DeploymentTime'))
            instance['DeploymentId'] = i.get('Deployment').get('DeploymentId')
            instance['DeploymentStatus'] = i.get('Deployment').get('Status')
            instance['DeploymentVersion'] = i.get('Deployment').get(
                'VersionLabel')

        instance['load1'] = instance['LoadAverage'][0] \
            if 'LoadAverage' in instance else '-'
        instance['load5'] = instance['LoadAverage'][1] \
            if 'LoadAverage' in instance else '-'

        instance['launched'] = utils.get_local_time_as_string(
            instance['LaunchedAt'])
        instance['running'] = format_time_since(instance['LaunchedAt'])

        duration = instance.get('Duration', 10)
        instance['requests'] = request_count / (duration * 1.0)

        for key in {'Status_2xx', 'Status_3xx', 'Status_4xx', 'Status_5xx'}:
            _convert_data_to_percentage(instance,
                                        key,
                                        request_count,
                                        add_sort_column=True)

        # Add status sort index
        instance['status_sort'] = __get_health_sort_order(
            instance['HealthStatus'])

        result.append(instance)

    return result
Beispiel #5
0
def collapse_instance_health_data(instances_health):
    instance_list = instances_health.get('InstanceHealthList', [])
    result = list()
    for i in instance_list:
        instance = dict()
        request_count = i.get('ApplicationMetrics', {}) \
            .get('RequestCount', 0)
        latency = i.get('ApplicationMetrics', {}).pop('Latency', {})
        instance.update(_format_latency_dict(latency, request_count))
        instance.update(i.get('ApplicationMetrics', {}).pop('StatusCodes', {}))
        instance.update(i.pop('ApplicationMetrics', {}))

        instance.update(i.get('System', {}).pop('CPUUtilization', {}))
        instance.update(i.pop('System', {}))
        instance.update(i)
        causes = instance.get('Causes', [])
        cause = causes[0] if causes else ''
        instance['Cause'] = cause

        instance['InstanceType'] = i.get('InstanceType')
        if i.get('AvailabilityZone'): #us-east-1a -> 1a
            try:
                instance['AvailabilityZone'] = i.get('AvailabilityZone').rsplit('-', 1)[-1]
            except:
                instance['AvailabilityZone'] = i.get('AvailabilityZone')
        if i.get('Deployment'):
            instance['TimeSinceDeployment'] = format_time_since(i.get('Deployment').get('DeploymentTime'))
            instance['DeploymentId'] = i.get('Deployment').get('DeploymentId')
            instance['DeploymentStatus'] = i.get('Deployment').get('Status')
            instance['DeploymentVersion'] = i.get('Deployment').get('VersionLabel')

        instance['load1'] = instance['LoadAverage'][0] \
            if 'LoadAverage' in instance else '-'
        instance['load5'] = instance['LoadAverage'][1] \
            if 'LoadAverage' in instance else '-'

        instance['launched'] = utils.get_local_time_as_string(instance['LaunchedAt'])
        instance['running'] = format_time_since(instance['LaunchedAt'])

        # Calculate requests per second
        duration = instance.get('Duration', 10)
        instance['requests'] = request_count / (duration * 1.0)

        # Convert counts to percentages
        for key in {'Status_2xx', 'Status_3xx', 'Status_4xx', 'Status_5xx'}:
            _convert_data_to_percentage(instance, key, request_count,
                                       add_sort_column=True)

        # Add status sort index
        instance['status_sort'] = __get_health_sort_order(instance['HealthStatus'])

        result.append(instance)

    return result
Beispiel #6
0
    def draw_banner_first_line(self, lines, data):
        status = data.get('HealthStatus', 'Unknown')
        refresh_time = data.get('RefreshedAt', None)
        if refresh_time is None:
            timestamp = '-'
            countdown = ' ( now )'
        else:
            timestamp = utils.get_local_time_as_string(refresh_time)
            delta = utils.get_delta_from_now_and_datetime(refresh_time)
            diff = 11 - delta.seconds
            if not self.refresh:
                countdown = ''
            elif self.frozen:
                countdown = ' (frozen +{})'.format(delta.seconds)
            elif diff < 0:
                countdown = ' ( now )'
            else:
                countdown = " ({} secs)".format(diff)
        env_name = data.get('EnvironmentName')
        pad_length = term.width() \
                     - len(env_name) \
                     - len(timestamp) \
                     - len(countdown) \
                     - 1
        if lines > 2:
            banner = io.bold(' {env_name}{status}{time}{cd} ') \
                .format(env_name=env_name,
                        status=status.center(pad_length),
                        time=timestamp,
                        cd=countdown,
                        )
            if not self.mono:
                banner = io.on_color(data.get('Color', 'Grey'), banner)
            term.echo_line(banner)

            lines -= 1
        return lines