Skip to content

Latest commit

 

History

History
183 lines (115 loc) · 6.07 KB

README.md

File metadata and controls

183 lines (115 loc) · 6.07 KB

CloudWatch code examples for the SDK for Python (Boto3)

Overview

Shows how to use the AWS SDK for Python (Boto3) to work with Amazon CloudWatch.

CloudWatch provides a reliable, scalable, and flexible monitoring solution that you can start using within minutes.

⚠ Important

  • Running this code might result in charges to your AWS account. For more details, see AWS Pricing and Free Tier.
  • Running the tests might result in charges to your AWS account.
  • We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see Grant least privilege.
  • This code is not tested in every AWS Region. For more information, see AWS Regional Services.

Code examples

Prerequisites

For prerequisites, see the README in the python folder.

Install the packages required by these examples by running the following in a virtual environment:

python -m pip install -r requirements.txt

Basics

Code examples that show you how to perform the essential operations within a service.

Single actions

Code excerpts that show you how to call individual service functions.

Scenarios

Code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

Run the examples

Instructions

Learn the basics

This example shows you how to do the following:

  • List CloudWatch namespaces and metrics.
  • Start OpenTelemetry enrichment so CloudWatch correlates incoming OTLP metrics with the resources that produced them.
  • See how OTLP metrics reach the CloudWatch metrics endpoint. Metric ingestion over OTLP is not an AWS SDK operation.
  • Create an alarm that evaluates a PromQL query.
  • Inspect the alarm's contributors, the individual series that the query matched.
  • Get statistics for a metric and chart it on a dashboard.
  • Mute the alarm for a maintenance window, then clean up.

Start the example by running the following at a command prompt:

python cloudwatch_scenario.py

Manage custom metrics and alarms

This example shows you how to do the following:

  • Create an alarm to watch a single CloudWatch metric.
  • Put data into the metric with PutMetricData and trigger the alarm.
  • Get data from the alarm.
  • Delete the alarm.

Start the example by running the following at a command prompt:

python cloudwatch_basics.py

Send OpenTelemetry metrics and alarm on them with PromQL

This example shows you how to do the following:

  • Send OTLP metrics to the CloudWatch metrics endpoint with an OpenTelemetry Collector.
  • Start OpenTelemetry enrichment so CloudWatch correlates those metrics with your resources.
  • Create an alarm that evaluates a PromQL query across every series the query returns.
  • Inspect the individual series, called contributors, that put the alarm in ALARM state.
  • Mute the alarm for a maintenance window, then clean up.

Start the example by running the following at a command prompt:

python cloudwatch_otel.py

Tests

⚠ Running tests might result in charges to your AWS account.

To find instructions for running these tests, see the README in the python folder.

Additional resources


Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0