Visualizing Amazon CloudWatch Costs – Part 2 – Where does the data come from?
In part 1 of this series we explored an Amazon CloudWatch dashboard which provides a real-time view of some of the typical main contributors to CloudWatch costs. In this second post, we’ll look at how the CloudWatch dashboard widgets were created so that you can learn how to create something similar, or modify the widgets to suit your needs.
For a description of the widgets and how to use them, see part 1 of this blog series.
Within this post, we’ll be describing how we worked with two main types of widgets: metric widgets and custom widgets. This isn’t an exhaustive explanation of these features. However, along with AWS documentation, it should get you started and give you the capability to create something similar yourself. Note that custom widgets require code to be developed – we’ll highlight key parts of the code, but we aren’t attempting to teach you to code or create AWS Lambda functions. You may need to use additional resources and AWS documentation to support your needs.
Note that for all of the examples here, only regions which don’t required an opt-in have been included. See the AWS documentation on Enabling a Region for further details.
Metric widgets – data by region
The log ingest volume, log event count, and API metric count widgets are all created using CloudWatch metrics available by default.
Metric widgets are created for various metrics as a total for each region individually, and a total across all regions. We do this by using a combination of Metric Math Expressions. We’ll look at the “Total Log Ingestion by Region: Volume (GB)” widget shown in the following figure.
Specifying more than one region can be achieved by modifying the metric source (see the following figure). This is a text editor where you can create the appropriate JSON for your widget. You can find the source tab when you create/edit a metric widget.
When you edit the source directly, remember to Save it (top right of the source code window – see the following screenshot). If you navigate away from the tab without doing this, then you’ll lose your changes. If your syntax is correct, then the Update Widget button will change from grey to orange after you Save. If it doesn’t change to orange, then there is likely an error in your source text.
The source for the “Total Ingestion by Region: Volume (GB)” widget, shows the following parts:
- The IncomingBytes metric from the AWS/Logs namespace for each region.
- A metric math expression to convert all of these from bytes to GB.