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?"