0
0
AWScloud~5 mins

Default vs custom metrics in AWS - Performance Comparison

Choose your learning style9 modes available
Time Complexity: Default vs custom metrics
O(n)
Understanding Time Complexity

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.

Scenario Under Consideration

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 Repeating Operations

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).
How Execution Grows With Input

As the number of metrics increases, the number of API calls grows roughly in direct proportion.

Input Size (n metrics)Approx. Api Calls/Operations
1010 calls
100100 calls
10001000 calls

Pattern observation: Doubling the number of metrics doubles the number of API calls needed.

Final Time Complexity

Time Complexity: O(n)

This means the work grows linearly with the number of metrics you handle.

Common Mistake

[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.

Interview Connect

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.

Self-Check

"What if we batch multiple custom metrics into a single API call? How would the time complexity change?"