Back to main page


Cloudwatch

Abstracted Boto3 Methods:

Usage

Batch put metric data to Cloudwatch.

The Cloudwatch client is intialised with the Namespace required.

To submit a custom Cloudwatch metric, provide the following information:

from boto3_batch_utils import CloudwatchBatchDispatcher


cw = CloudwatchBatchDispatcher('TestService')

cw.submit_metric('DoingACountMetric', value=555)
cw.submit_metric('DoingACountMetric', value=4, unit='Seconds')

unprocessed_records = cw.flush_payloads()

Cloudwatch comes with a handy dimension builder function cloudwatch_dimension to help you construct dimensions (see below).

Advanced Usage

The Cloudwatch client can be used very simply. However, you can gain additional control with the following advanced features:

Batch Size

For information about batch sizes click here.

The Cloudwatch client has the following maximum batch limitations:

Limit Type Limit
Number of Records 150
Byte size of a single record 40,960 bytes
Byte size of a batch 40,960 bytes
Dimensions Per Metric 10

Dimensions

Cloudwatch Metrics Dimensions are optional. If required between one and ten dimensions may be used. Boto3 Batch Utils provides a helper function cloudwatch_dimension to correctly format dimensions. The inputs to this helper function are:

from boto3_batch_utils import CloudwatchBatchDispatcher, cloudwatch_dimension as cd


cw = CloudwatchBatchDispatcher('TestService')

cw.submit_metric('DoingACountMetric', value=1234, dimensions=cd('dimA', '12345'))
cw.submit_metric('DoingASecondsMetric', value=978, dimensions=[cd('timeA', '11'), cd('timeB', '4')])

cw.flush_payloads()

Uniqueness

When a record is submitted to the Cloudwatch client using submit_metric it is NOT checked for uniqueness. When sending data to Cloudwatch Metrics Stream, it is both likely and valid to send duplicate metric payloads.


Back to main page