Default vs custom metrics in AWS - Performance Comparison
When working with AWS monitoring, it is important to understand how the time to collect and process metrics changes as you add more metrics.
We want to know how the number of metrics affects the work AWS does behind the scenes.
Analyze the time complexity of the following operation sequence.
# Fetch default metrics for EC2 instances
aws cloudwatch get-metric-data --metric-data-queries '[{"Id":"m1","MetricStat":{"Metric":{"Namespace":"AWS/EC2","MetricName":"CPUUtilization","Dimensions":[{"Name":"InstanceId","Value":"i-1234567890abcdef0"}]},"Period":300,"Stat":"Average"},"ReturnData":true},{"Id":"m2","MetricStat":{"Metric":{"Namespace":"AWS/EC2","MetricName":"NetworkIn","Dimensions":[{"Name":"InstanceId","Value":"i-1234567890abcdef0"}]},"Period":300,"Stat":"Sum"},"ReturnData":true},{"Id":"m3","MetricStat":{"Metric":{"Namespace":"AWS/EC2","MetricName":"NetworkOut","Dimensions":[{"Name":"InstanceId","Value":"i-1234567890abcdef0"}]},"Period":300,"Stat":"Sum"},"ReturnData":true}]'
# Publish custom metrics for application
aws cloudwatch put-metric-data --namespace MyApp --metric-name RequestCount --value 1
aws cloudwatch put-metric-data --namespace MyApp --metric-name ErrorCount --value 0
This sequence fetches default metrics automatically provided by AWS and sends custom metrics created by the user.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Fetching or sending each metric data point via CloudWatch API calls.
- How many times: Once per metric per time interval (e.g., per minute).
As the number of metrics increases, the number of API calls grows roughly in direct proportion.
| Input Size (n metrics) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 calls |
| 100 | 100 calls |
| 1000 | 1000 calls |
Pattern observation: Doubling the number of metrics doubles the number of API calls needed.
Time Complexity: O(n)
This means the work grows linearly with the number of metrics you handle.
[X] Wrong: "Adding more custom metrics won't affect performance much because AWS handles it automatically."
[OK] Correct: Each metric requires separate API calls and processing, so more metrics mean more work and longer processing times.
Understanding how monitoring scales with the number of metrics helps you design efficient cloud systems and shows you can think about cost and performance together.
"What if we batch multiple custom metrics into a single API call? How would the time complexity change?"
Practice
Solution
Step 1: Understand default metrics collection
AWS CloudWatch automatically collects default metrics for many services without extra setup.Step 2: Recognize cost and availability
These default metrics are free within certain usage limits, making them easy to use.Final Answer:
They are automatically collected and free within certain limits. -> Option AQuick Check:
Default metrics = automatic + free [OK]
- Thinking default metrics need manual setup
- Assuming default metrics track custom data
- Believing default metrics are disabled by default
Solution
Step 1: Identify the correct AWS CLI command
The correct command to send custom metric data isput-metric-dataunderaws cloudwatch.Step 2: Check the syntax and parameters
The command requires--metric-name,--namespace, and--valueparameters as shown in aws cloudwatch put-metric-data --metric-name CPUUtilization --namespace AWS/EC2 --value 70.Final Answer:
aws cloudwatch put-metric-data --metric-name CPUUtilization --namespace AWS/EC2 --value 70 -> Option DQuick Check:
Use put-metric-data with metric-name and namespace [OK]
- Using incorrect command names like send-metric or create-metric
- Omitting the namespace parameter
- Confusing metric creation with data sending
aws cloudwatch put-metric-data --metric-name PageViews --namespace MyApp --value 5
What will be the average value shown in CloudWatch after 3 minutes if the command is run 3 times with values 5, 7, and 8 respectively?
Solution
Step 1: Sum the metric values sent
The values sent are 5, 7, and 8. Their sum is 5 + 7 + 8 = 20.Step 2: Calculate the average over 3 data points
Average = Total sum / Number of data points = 20 / 3 ≈ 6.67.Final Answer:
6.67 -> Option AQuick Check:
Average = sum/3 = 6.67 [OK]
- Adding values but not dividing by count
- Taking the last value as average
- Multiplying values instead of averaging
Solution
Step 1: Check required parameters for custom metrics
Custom metrics require a namespace to organize and display them properly in CloudWatch.Step 2: Understand impact of missing namespace
If the namespace is missing, CloudWatch cannot categorize the metric, so it won't appear in the console.Final Answer:
You forgot to specify the metric namespace in the command. -> Option BQuick Check:
Missing namespace hides custom metric [OK]
- Assuming default metrics need namespaces
- Expecting immediate visibility without data sent
- Believing CloudWatch delays metric display by 24 hours
Solution
Step 1: Identify the need for custom data
User logins per hour is specific to the application and not tracked by default AWS metrics.Step 2: Use custom metrics for application-specific data
Sending custom metric data with a unique namespace and metric name allows tracking exactly this information in CloudWatch.Final Answer:
Send custom metric data for user logins to CloudWatch using a unique namespace and metric name. -> Option CQuick Check:
Custom metrics track app-specific data [OK]
- Trying to use unrelated default metrics for app data
- Assuming detailed monitoring tracks application events
- Using alarms on unrelated metrics to guess user activity
Ready to prove it?
Pass the test and this pattern moves unknown
