Concepts

Custom metrics are the user-defined metrics that you create to monitor the specific aspects of your application. AWS provides a service called Amazon CloudWatch that enables you to publish your own metrics. These can be anything from the number of user sign-ups to the execution duration of a particular piece of code.

To publish custom metrics to CloudWatch, you can use the AWS SDK or the CloudWatch API. For example, here’s how you might send a custom metric using the AWS SDK for Python (Boto3):

import boto3

cloudwatch = boto3.client(‘cloudwatch’)

cloudwatch.put_metric_data(
MetricData=[
{
‘MetricName’: ‘CompletedTransactions’,
‘Dimensions’: [
{
‘Name’: ‘ServiceName’,
‘Value’: ‘CheckoutService’
},
],
‘Unit’: ‘Count’,
‘Value’: 100.0
},
],
Namespace=’MyApp’
)

This snippet creates a custom metric called CompletedTransactions for the CheckoutService and logs 100 completed transactions.

Embedded Metrics

Embedded metrics are part of the Embedded Metric Format (EMF) provided by AWS, which allows you to embed custom metrics within your application’s log messages. When you use EMF, CloudWatch can extract the metrics from the log data, enabling you to analyze both logs and metrics together.

Here’s an example of a JSON structure you might log to embed a custom metric:

{
“_aws”: {
“Timestamp”: 1592466344000,
“CloudWatchMetrics”: [
{
“Namespace”: “MyApp”,
“Dimensions”: [[“ServiceName”]],
“Metrics”: [
{“Name”: “ProcessingLatency”, “Unit”: “Milliseconds”}
]
}
]
},
“ServiceName”: “DataProcessingService”,
“ProcessingLatency”: 500
}

When AWS CloudWatch processes this log, it will extract the ProcessingLatency metric for the DataProcessingService.

Built-in Metrics

Built-in metrics are automatically collected and generated by AWS services. For instance, Amazon EC2 automatically publishes data points for CPU utilization, disk reads/writes, and network bandwidth utilization. You don’t need to do anything to enable built-in metrics, as they are a standard part of using AWS services.

Here’s a comparative view of the key aspects of custom, embedded, and built-in metrics:

Metric Type Origin Configuration Required Use Case
Custom Metrics User-defined Yes Track specific application metrics
Embedded Metrics Logs (Using EMF) Yes (Log format) Correlate logs and metrics
Built-in Metrics AWS Services No Monitor AWS resource utilization

Summary

As an AWS Certified Developer, you must understand when and how to use these different types of metrics. Custom and embedded metrics give you the flexibility to measure application-specific metrics that are not captured by built-in AWS metrics. Built-in metrics, however, provide an easy and automatic way to monitor the health and performance of underlying AWS resources.

To effectively use these metrics, you can set up CloudWatch alarms to notify you when certain thresholds are breached, or use CloudWatch Dashboard to create a visual representation of your application’s health and performance over time. Understanding how to employ these metrics helps to ensure your application is performant, scalable, and reliable.

Answer the Questions in Comment Section

True or False: It’s possible to monitor AWS Lambda function execution times using Amazon CloudWatch.

  • (a) True
  • (b) False

Answer: (a) True

Explanation: AWS Lambda metrics such as the execution time are automatically monitored and sent to Amazon CloudWatch.

Which service can you use to collect system-level metrics from Amazon EC2 instances?

  • (a) AWS X-Ray
  • (b) AWS CloudTrail
  • (c) Amazon CloudWatch
  • (d) Amazon S3

Answer: (c) Amazon CloudWatch

Explanation: Amazon CloudWatch can be used to collect monitoring and operational data in the form of logs, metrics, and events.

True or False: Amazon CloudWatch can only monitor AWS resources.

  • (a) True
  • (b) False

Answer: (b) False

Explanation: Amazon CloudWatch can monitor both AWS resources and the applications you run within them.

Which AWS service provides application-level metrics and traces?

  • (a) AWS X-Ray
  • (b) AWS CloudTrail
  • (c) Amazon ECS
  • (d) AWS IAM

Answer: (a) AWS X-Ray

Explanation: AWS X-Ray helps developers analyze and debug distributed applications, such as those built using a microservices architecture.

True or False: AWS CloudTrail is primarily used for auditing API calls and compliance monitoring.

  • (a) True
  • (b) False

Answer: (a) True

Explanation: AWS CloudTrail is mainly used for logging and tracking API calls made within AWS, making it a valuable resource for auditing and compliance.

What must you do to enable detailed monitoring for an Amazon EC2 instance?

  • (a) Modify the instance IAM role
  • (b) Change the instance EBS volume type to Provisioned IOPS
  • (c) Install the Amazon CloudWatch agent
  • (d) Enable detailed monitoring in the instance settings

Answer: (d) Enable detailed monitoring in the instance settings

Explanation: Detailed monitoring for an EC2 instance can be enabled by changing the monitoring settings in the EC2 dashboard.

True or False: Amazon CloudWatch Logs can store logs indefinitely.

  • (a) True
  • (b) False

Answer: (a) True

Explanation: Amazon CloudWatch Logs allows users to define the retention period for logs, and logs can be stored indefinitely by setting the retention to “Never Expire.”

Which AWS feature allows tracking user activity and API usage across AWS infrastructure?

  • (a) AWS Config
  • (b) AWS CloudFormation
  • (c) AWS Trusted Advisor
  • (d) AWS CloudTrail

Answer: (d) AWS CloudTrail

Explanation: AWS CloudTrail is designed to track user activity and API usage across AWS infrastructure.

True or False: Embedded metrics in your application code cannot be sent directly to Amazon CloudWatch.

  • (a) True
  • (b) False

Answer: (b) False

Explanation: You can embed custom metrics in your application code and use the PutMetricData API to send them directly to Amazon CloudWatch.

To create custom metrics in Amazon CloudWatch, what namespace should be used?

  • (a) Any AWS service namespace
  • (b) A namespace specific to your AWS account
  • (c) A predefined CloudWatch namespace
  • (d) A custom namespace that you define

Answer: (d) A custom namespace that you define

Explanation: Custom metrics require a custom namespace that you define to distinguish them from AWS service metrics.

True or False: Amazon CloudWatch Events and Amazon EventBridge are different services for event-driven computing on AWS.

  • (a) True
  • (b) False

Answer: (b) False

Explanation: Amazon CloudWatch Events has been renamed to Amazon EventBridge, and it provides the same capabilities for event-driven computing on AWS.

Which metric data granularity level(s) does Amazon CloudWatch support?

  • (a) 1-minute granularity
  • (b) 5-minute granularity
  • (c) 1-second granularity
  • (d) Both (a) and (b)

Answer: (d) Both (a) and (b)

Explanation: Amazon CloudWatch supports 1-minute granularity for detailed monitoring and 5-minute granularity for basic monitoring.

0 0 votes
Article Rating
Subscribe
Notify of
guest
24 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Travis Bryant
7 months ago

Great blog post! Application metrics are super important for monitoring performance. Thanks for sharing.

Ishana Keshri
7 months ago

Does the AWS Certified Developer exam cover how to implement custom metrics in CloudWatch?

Guadalupe Roybal
7 months ago

Thanks for the information, really helpful for my preparation.

Megan Park
7 months ago

I believe built-in metrics are often good enough for small applications, would you agree?

Veselin Marinković
6 months ago

Excellent overview of application metrics. Appreciated!

Debbie Mason
8 months ago

Does anyone have experience embedding metrics from AWS CloudWatch into a custom dashboard?

Garance Brun
6 months ago

Nice article! Custom metrics can get pricey, though. Any cost-saving tips?

Ege Avan
7 months ago

I encountered some issues with missing custom metrics in CloudWatch, any advice?

24
0
Would love your thoughts, please comment.x
()
x