AWS CloudWatch provides extensive monitoring services for AWS resources and customer-run applications. It primarily focuses on two types of metrics: built-in and custom metrics.

Table of Contents

Built-in Metrics

Built-in metrics are automatically sent by AWS services to CloudWatch. Each AWS service that integrates with CloudWatch sends a unique set of metrics, varying in usefulness according to the nature of the service. For example, an EC2 instance sends metrics related to CPU usage, network packets, and disk read operations.

Custom Metrics

Unlike built-in metrics, custom metrics are not generated automatically. They are defined by the user depending on specific monitoring needs. For example, a developer might want to monitor an application-specific metric, like the number of unique users per minute on a web application.

Here is a simple Python code example using the Boto3 SDK for creating a custom metric:

import boto3

cloudwatch = boto3.client('cloudwatch')

cloudwatch.put_metric_data(
MetricData = [
{
'MetricName': 'PAGES_VISITED',
'Dimensions': [
{
'Name': 'UNIQUE_VISITORS',
'Value': 'Count'
},
],
'Unit': 'None',
'Value': 1.0
},
],
Namespace = 'SITE/TRAFFIC'
)

In this code, we are creating a custom metric PAGES_VISITED with a dimension UNIQUE_VISITORS.

AWS X-Ray: Embedded Metrics

AWS X-Ray helps developers analyze and debug distributed applications, such as those built using a microservices architecture. Within this context of application tracking, embedded metrics are crucial.

Embedded metrics are those that are incorporated directly into applications’ business and operational codes. They can track any information the developer considers important such as the number of items in a shopping cart, response times of a database, error rates, etc.

While AWS does not natively generate embedded metrics in your application, you can use AWS SDKs for instrumentation.

import boto3
from aws_xray_sdk.core import xray_recorder

@xray_recorder.capture('My function')
def my_function():
# Your code here

In the Python code above, we are using the AWS X-Ray SDK to instrument a function `my_function`. With this, we embed the X-Ray tracing within our code to track its execution and performance.

Conclusion

Application metrics, whether they are custom, embedded, or built-in, play a significant role in monitoring application performance in real-time. Gaining a strong grasp of these concepts not only helps in the AWS Certified Developer – Associate exam preparation but also significantly contributes to effective administration and development in the AWS ecosystem. The ability to deploy, use, interpret, and optimize these metrics can drastically enhance your web services.

Practice Test

True or False: Custom and built-in metrics have the same retention period in AWS CloudWatch.

  • True
  • False

Answer: False

Explanation: In AWS CloudWatch, the custom metrics have a retention period of 15 months, whereas the built-in metrics are retained for 15 months.

Which of the following is an Amazon RDS Database built-in metric?

  • a. DBConnections
  • b. DBMemory
  • c. DBDisk
  • d. None of the above

Answer: a. DBConnections

Explanation: DBConnections is an Amazon RDS built-in metric that measures the number of database connections.

True or False: In AWS, you can only create custom metrics using the AWS SDK.

  • True
  • False

Answer: False

Explanation: Apart from AWS SDK, you can also create custom metrics using AWS CLI and CloudWatch API.

Which of the following cannot be done with custom metrics in AWS?

  • a. Analyze logs for specific phrases or values
  • b. Set alarms
  • c. View graphical representation
  • d. None of the above

Answer: d. None of the above

Explanation: All the options mentioned – analyzing logs for specific phrases or values, setting alarms, and viewing graphical representations, can be done with custom metrics in AWS.

True or False: In AWS, metrics are regional, meaning the metrics are not shared across regions.

  • True
  • False

Answer: True

Explanation: Each AWS region is completely independent. Therefore, metrics are not shared across regions.

AWS Elastic Load Balancer has which of the following built-in metrics?

  • a. Latency
  • b. RequestCount
  • c. BackendConnectionErrors
  • d. All of the above

Answer: d. All of the above

Explanation: All three options mentioned – Latency, RequestCount, and BackendConnectionErrors are built-in metrics for AWS Elastic Load Balancer.

True or False: You cannot retrieve both statistics and metric data with one query using GetMetricData.

  • True
  • False

Answer: False

Explanation: The GetMetricData operation allows you to retrieve both statistics and metric data in a single request.

Which of the following are types of custom metrics in AWS?

  • a. High-resolution metrics
  • b. Dimensional metrics
  • c. Standard-resolution metrics
  • d. All of the above

Answer: d. All of the above

Explanation: Amazon CloudWatch supports all three – high-resolution metrics, dimensional metrics, and standard-resolution metrics as types of custom metrics.

Which of the following built-in metrics is not associated with Amazon EC2?

  • a. CPUUtilization
  • b. NetworkPacketsOut
  • c. VolumeReadBytes
  • d. DiskReadOps

Answer: c. VolumeReadBytes

Explanation: VolumeReadBytes is a built-in metric associated with Amazon EBS (Elastic Block Store) and not Amazon EC

True or False: Amazon CloudWatch metrics are kept indefinitely.

  • True
  • False

Answer: False

Explanation: The CloudWatch retention period varies from 15 days to 15 months depending on the type of data.

Interview Questions

1. Which AWS service do developers use for publishing, storing, and monitoring application metrics?

Developers use Amazon CloudWatch to publish, store, and monitor application metrics.

2. How can you create custom application metrics using CloudWatch?

Custom application metrics can be created in CloudWatch using the PutMetricData API.

3. What is the purpose of embedded metrics in AWS?

Embedded metrics format (EMF) in AWS enables you to ingest complex high-cardinality application data in the form of logs and convert them into CloudWatch Metrics, which you can use for extracting actionable insights.

4. What significance do built-in metrics have in the AWS ecosystem?

Built-in metrics provide automatic insights into the performance and health of AWS resources which can be used for troubleshooting issues, and performance tuning.

5. In the context of monitoring an AWS Lambda function, which metric can give you the total time used by the function to run during the measurement period?

The metric that can provide this information is known as “Duration”.

6. What are the three statuses a check can report in Amazon Route 53?

The three statuses a check can report in Amazon Route 53 are “Healthy”, “Unhealthy”, and “Unknown”.

7. In Amazon CloudWatch, what is the maximum resolution for a custom metric?

The maximum resolution for a custom metric in CloudWatch is one data point per second.

8. If I’m concerned about the maximum number of read and write queries an Amazon RDS instance can handle, which built-in metrics should I follow?

Assessing “ReadThroughput” and “WriteThroughput” metrics gives the maximum number of read and write queries handled by an Amazon RDS instance.

9. What type of data is represented by application metrics in AWS CloudWatch?

Application metrics in AWS CloudWatch typically represent the time-series data.

10. Which operating system metrics are important to monitor when using Amazon EC2?

Some important EC2 OS metrics include CPU utilization, memory usage, disk I/O, and network I/O.

11. What is the default retention period for AWS CloudWatch Logs data?

The default retention period for AWS CloudWatch Logs data is indefinitely (until they are manually deleted).

12. Which operation do you use to send custom metrics data to CloudWatch?

The “PutMetricData” operation is used to send custom metrics data to CloudWatch.

13. How is it possible to monitor custom application metrics like the number of user logins in AWS?

We can use either CloudWatch custom metrics or EMF (Embedded metric format) in logs to monitor such custom application metrics.

14. Can you provide an example of a high-resolution metric in AWS CloudWatch?

A metric with a period of less than 60 seconds is known as a high-resolution metric in AWS CloudWatch.

15. Are you able to customize the period of data reporting when creating custom CloudWatch metrics?

Yes, you can customize the period for your data reporting when using custom CloudWatch metrics. The period can be as short as one second or as long as one day.

Leave a Reply

Your email address will not be published. Required fields are marked *