Cloudwatch
Abstracted Boto3 Methods:
put_metric_data()
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:
metric_name
: The name of the metric which the data will be associated with. See Metrics for more information.value
: The value of the metric.timestamp
: (Optional) Defaults tonow()
. The timestamp for when the metric is pertinent.dimensions
: (Optional) See Dimensions for more information. Provide either acloudwatch_dimension
or a list of multiplecloudwatch_dimension
.unit
: (Optional) Defaults toCount
. For more information see Metric Datum. Any of the following values may be provided:Seconds | Microseconds | Milliseconds | Bytes | Kilobytes | Megabytes | Gigabytes | Terabytes | Bits | Kilobits | Megabits | Gigabits | Terabits | Percent | Count | Bytes/Second | Kilobytes/Second | Megabytes/Second | Gigabytes/Second | Terabytes/Second | Bits/Second | Kilobits/Second | Megabits/Second | Gigabits/Second | Terabits/Second | Count/Second | None
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:
name
: The name of the dimension.value
: The value of the dimension.
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.