cwadapter

Reports timer statistics to AWS CloudWatch Metrics.

class backpack.cwadapter.CloudWatchTimerAdapter(namespace, metric_name, dimensions=None, region=None, boto3_session=None, parent_logger=None)

Bases: object

Reports timer statistics to AWS CloudWatch Metrics.

The IAM policy associated with the Panorama Application Role of this app should grant the execution of cloudwatch:PutMetricData operation.

Parameters:
  • namespace (str) – The name of the CloudWatch namespace of this custom metrics. It can be for example the name of your project.

  • metric_name (str) – The name of the CloudWatch metrics. This can be for example frame_processing_time, if you use CWTachometer to measure frame processing time statistics.

  • dimensions (Optional[Dict[str, str]]) – Additional CloudWatch metrics dimensions of this metric. This can be for example the device and application identifier.

  • region (Optional[str]) – The AWS region of the CloudWatch metrics.

  • boto3_session (Optional[boto3.Session]) – The boto3 session to be used for sending the CloudWatch metrics. If left to None, CWTachometer will use the default session. If the default session does not have a default region configured, you might get errors.

  • parent_logger (Optional[logging.Logger]) – If you want to connect the logger of this class to a parent, specify it here.

send_metrics(timestamp, timer)

Sends timer statistics to CloudWatch.

This method can be used as a callback in Tachometer instances.

For example:

cw_adapter = CloudWatchTimerAdapter(
    namespace='my_namespace',
    metric_name='my_metric',
    dimensions={'foo': 'bar'}
)
tacho = TickerTachometer(
    stats_callback=cw_adapter.send_metrics
)
tacho.tick()
Parameters:
  • timestamp (datetime.datetime) – The timestamp the statistics refers to.

  • timer (BaseTimer) – The timer that collected the statistics.

Return type:

None