def __get_aws_metric(table_name, gsi_name, time_frame, metric_name): """ Returns a metric list from the AWS CloudWatch service, may return None if no metric exists :type table_name: str :param table_name: Name of the DynamoDB table :type gsi_name: str :param gsi_name: Name of a GSI on the given DynamoDB table :type time_frame: int :param time_frame: How many seconds to look at :type metric_name str :param metric_name Name of the metric to retrieve from CloudWatch :returns: list -- A list of time series data for the given metric, may be None if there was no data """ try: start_time = datetime.utcnow()-timedelta(minutes=10, seconds=time_frame) end_time = datetime.utcnow()-timedelta(minutes=10) return cloudwatch_connection.get_metric_statistics( period=time_frame, start_time=start_time, end_time=end_time, metric_name=metric_name, namespace='AWS/DynamoDB', statistics=['Sum'], dimensions={ 'TableName': table_name, 'GlobalSecondaryIndexName': gsi_name }, unit='Count') except BotoServerError: raise
def __get_aws_metric(table_name, time_frame, metric_name): """ Returns a metric list from the AWS CloudWatch service, may return None if no metric exists :type table_name: str :param table_name: Name of the DynamoDB table :type time_frame: int :param time_frame: How many seconds to look at :type metric_name str :param metric_name Name of the metric to retrieve from CloudWatch :returns: list -- A list of time series data for the given metric, may be None if there was no data """ try: start_time = datetime.utcnow()-timedelta(minutes=10, seconds=time_frame) end_time = datetime.utcnow()-timedelta(minutes=10) return cloudwatch_connection.get_metric_statistics( period=time_frame, start_time=start_time, end_time=end_time, metric_name=metric_name, namespace='AWS/DynamoDB', statistics=['Sum'], dimensions={'TableName': table_name}, unit='Count') except BotoServerError as error: logger.error( 'Unknown boto error. Status: "{0}". ' 'Reason: "{1}". Message: {2}'.format( error.status, error.reason, error.message)) raise
def __get_aws_metric(table_name, lookback_window_start, metric_name): """ Returns a metric list from the AWS CloudWatch service, may return None if no metric exists :type table_name: str :param table_name: Name of the DynamoDB table :type lookback_window_start: int :param lookback_window_start: How many minutes to look at :type metric_name: str :param metric_name: Name of the metric to retrieve from CloudWatch :returns: list -- A list of time series data for the given metric, may be None if there was no data """ try: now = datetime.utcnow() start_time = now - timedelta(minutes=lookback_window_start) end_time = now - timedelta(minutes=lookback_window_start - 5) return cloudwatch_connection.get_metric_statistics( period=300, # Always look at 5 minutes windows start_time=start_time, end_time=end_time, metric_name=metric_name, namespace='AWS/DynamoDB', statistics=['Sum'], dimensions={'TableName': table_name}, unit='Count') except BotoServerError as error: logger.error('Unknown boto error. Status: "{0}". ' 'Reason: "{1}". Message: {2}'.format( error.status, error.reason, error.message)) raise
def __get_aws_metric(table_name, gsi_name, time_frame, metric_name): """ Returns a metric list from the AWS CloudWatch service, may return None if no metric exists :type table_name: str :param table_name: Name of the DynamoDB table :type gsi_name: str :param gsi_name: Name of a GSI on the given DynamoDB table :type time_frame: int :param time_frame: How many seconds to look at :type metric_name str :param metric_name Name of the metric to retrieve from CloudWatch :returns: list -- A list of time series data for the given metric, may be None if there was no data """ try: start_time = datetime.utcnow() - timedelta(minutes=10, seconds=time_frame) end_time = datetime.utcnow() - timedelta(minutes=10) return cloudwatch_connection.get_metric_statistics( period=time_frame, start_time=start_time, end_time=end_time, metric_name=metric_name, namespace='AWS/DynamoDB', statistics=['Sum'], dimensions={ 'TableName': table_name, 'GlobalSecondaryIndexName': gsi_name }, unit='Count') except BotoServerError: raise
def __get_aws_metric(table_name, gsi_name, lookback_window_start, lookback_period, metric_name): """ Returns a metric list from the AWS CloudWatch service, may return None if no metric exists :type table_name: str :param table_name: Name of the DynamoDB table :type gsi_name: str :param gsi_name: Name of a GSI on the given DynamoDB table :type lookback_window_start: int :param lookback_window_start: How many minutes to look at :type lookback_period: int :type lookback_period: Length of the lookback period in minutes :type metric_name: str :param metric_name: Name of the metric to retrieve from CloudWatch :returns: list -- A list of time series data for the given metric, may be None if there was no data """ try: now = datetime.utcnow() start_time = now - timedelta(minutes=lookback_window_start) end_time = now - timedelta( minutes=lookback_window_start - lookback_period) return cloudwatch_connection.get_metric_statistics( period=lookback_period * 60, start_time=start_time, end_time=end_time, metric_name=metric_name, namespace='AWS/DynamoDB', statistics=['Sum'], dimensions={ 'TableName': table_name, 'GlobalSecondaryIndexName': gsi_name }, unit='Count') except BotoServerError as error: logger.error( 'Unknown boto error. Status: "{0}". ' 'Reason: "{1}". Message: {2}'.format( error.status, error.reason, error.message)) raise