def get_consumed_read_units(table_name, time_frame=300):
    """ Returns the number of consumed read units

    :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
    :returns: int -- Number of consumed reads
    """
    metrics = cloudwatch_connection.get_metric_statistics(
        time_frame,
        datetime.utcnow()-timedelta(minutes=10, seconds=time_frame),
        datetime.utcnow()-timedelta(minutes=10),
        'ConsumedReadCapacityUnits',
        'AWS/DynamoDB',
        ['Sum'],
        dimensions={'TableName': table_name},
        unit='Count')

    if metrics:
        consumed_read_units = int(
            math.ceil(float(metrics[0]['Sum'])/float(time_frame)))
    else:
        consumed_read_units = 0

    logger.info('{0} - Consumed read units: {1:d}'.format(
        table_name, consumed_read_units))
    return consumed_read_units
Ejemplo n.º 2
0
def get_consumed_read_units(table_name, time_frame=300):
    """ Returns the number of consumed read units

    :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
    :returns: int -- Number of consumed reads
    """
    metrics = cloudwatch_connection.get_metric_statistics(
        time_frame,
        datetime.utcnow() - timedelta(minutes=10, seconds=time_frame),
        datetime.utcnow() - timedelta(minutes=10),
        'ConsumedReadCapacityUnits',
        'AWS/DynamoDB', ['Sum'],
        dimensions={'TableName': table_name},
        unit='Count')

    if metrics:
        consumed_read_units = int(
            math.ceil(float(metrics[0]['Sum']) / float(time_frame)))
    else:
        consumed_read_units = 0

    logger.info('{0} - Consumed read units: {1:d}'.format(
        table_name, consumed_read_units))
    return consumed_read_units
def get_consumed_read_units_percent(table_name, time_frame=300):
    """ Returns the number of consumed read units in percent

    :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
    :returns: int -- Number of consumed reads
    """
    metrics = cloudwatch_connection.get_metric_statistics(
        period=time_frame,
        start_time=datetime.utcnow()-timedelta(minutes=10, seconds=time_frame),
        end_time=datetime.utcnow()-timedelta(minutes=10),
        metric_name='ConsumedReadCapacityUnits',
        namespace='AWS/DynamoDB',
        statistics=['Sum'],
        dimensions={'TableName': table_name},
        unit='Count')

    if metrics:
        consumed_read_units = int(
            math.ceil(float(metrics[0]['Sum'])/float(time_frame)))
    else:
        consumed_read_units = 0

    consumed_read_units_percent = int(math.ceil(
            float(consumed_read_units) / \
            float(get_provisioned_read_units(table_name)) * \
            100))

    logger.info('{0} - Consumed read units: {1:d}%'.format(
        table_name, consumed_read_units_percent))
    return consumed_read_units_percent
Ejemplo n.º 4
0
def get_consumed_read_units_percent(table_name, time_frame=300):
    """ Returns the number of consumed read units in percent

    :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
    :returns: int -- Number of consumed reads
    """
    metrics = cloudwatch_connection.get_metric_statistics(
        period=time_frame,
        start_time=datetime.utcnow() -
        timedelta(minutes=10, seconds=time_frame),
        end_time=datetime.utcnow() - timedelta(minutes=10),
        metric_name='ConsumedReadCapacityUnits',
        namespace='AWS/DynamoDB',
        statistics=['Sum'],
        dimensions={'TableName': table_name},
        unit='Count')

    if metrics:
        consumed_read_units = int(
            math.ceil(float(metrics[0]['Sum']) / float(time_frame)))
    else:
        consumed_read_units = 0

    consumed_read_units_percent = int(math.ceil(
            float(consumed_read_units) / \
            float(get_provisioned_read_units(table_name)) * \
            100))

    logger.info('{0} - Consumed read units: {1:d}%'.format(
        table_name, consumed_read_units_percent))
    return consumed_read_units_percent