All data in CloudWatch is recorded with a specific namespace format. Default metrics are formatted as Service:Metric. For example, the CPU Utilization for the EC2 instances is represented by the following namespace: EC2:CPUUtilization.
Dimensions are key:value pairs assigned to metrics to allow for a more granular analysis of those metrics within a specific namespace. CloudWatch allows you to create 10 dimensions for each metric. However, some services have built-in dimensions, and they also count against the limit of 10. For example, the CPU Utilization for a specific EC2 instance with the ID i-111aaa222bbb333ccc is represented by the following namespace and dimension: EC2:CPUUtilization:InstanceId:i-111aaa222bbb333ccc.
CloudWatch supports custom namespaces that can contain up to 256 alphanumeric characters, periods, hyphens, underscores, forward slashes, hashes, and colons, meaning you can create your own structure for custom metrics. However, it is always a good idea to follow the structure AWS uses for its own services when implementing custom metric namespaces.
CloudWatch namespaces and dimensions can be used to drill down into specific resources metrics and graph them in the management console, as shown in Figure 2.1.
FIGURE 2.1 CloudWatch Namespaces and Dimensions
A metric represents any data point collected at a certain point in time. A metric has a value and a unit. AWS automatically generates standard metrics with a resolution of five minutes; however, some services support detailed metrics collected on a one-minute interval. Custom metrics are also supported and can be recorded as frequently as one second apart (high-resolution metrics).
CloudWatch metrics are retained for 15 months with the following retention periods:
Custom, subminute metrics are aggregated to minute metrics after 3 hours.
One-minute metrics are aggregated to 5-minute metrics after 15 days.
Five-minute metrics are aggregated to hourly metrics after 63 days.
Hourly metrics aggregates are discarded after 15 months.
If you are required to maintain metrics for a longer period of time, CloudWatch does offer the capability to export metrics to S3.
While the default metrics retention period is 15 months, the retention of logs in CloudWatch is indefinite. Therefore, you need to specifically delete the logs from CloudWatch. If you wish to automatically truncate the history of the logs retaine in CloudWatch, you can also set the retention period to between 1 and 10 years.
Over time, AWS creates statistics of all metrics, with the following aggregation approach:
Minimum: The lowest value within a certain period
Maximum: The highest value within a certain period
Sum: The sum of all values within a certain period
Average: An average of all values within a certain period
SampleCount: The number of values within a certain period
pNN.NN: The value of the percentile (for example, up-time percentage) up to 2 decimal points
These metrics can be used to understand the normal operational pattern of your application and to detect issues or even possible cost optimization opportunities.