0
0
AWScloud~5 mins

Default vs custom metrics in AWS - CLI Comparison

Choose your learning style9 modes available
Introduction
Metrics help you watch how your cloud resources behave. Default metrics are ready-made and track basic things automatically. Custom metrics let you track special details that matter to your app or service.
When you want to see CPU or memory use of your server without extra setup
When you need to track how many users logged into your app every hour
When you want to monitor error rates specific to your application logic
When you want alerts on unusual activity not covered by default metrics
When you want to compare performance between different versions of your app
Commands
This command lists default metrics for EC2 instances that AWS collects automatically.
Terminal
aws cloudwatch list-metrics --namespace AWS/EC2
Expected OutputExpected
METRICS { "Metrics": [ { "Namespace": "AWS/EC2", "MetricName": "CPUUtilization", "Dimensions": [ { "Name": "InstanceId", "Value": "i-0123456789abcdef0" } ] }, { "Namespace": "AWS/EC2", "MetricName": "DiskReadOps", "Dimensions": [ { "Name": "InstanceId", "Value": "i-0123456789abcdef0" } ] } ] }
--namespace - Filters metrics to show only those in the AWS/EC2 category
This command sends a custom metric named UserLogins with a value of 5 to CloudWatch under the CustomApp namespace.
Terminal
aws cloudwatch put-metric-data --namespace CustomApp --metric-name UserLogins --value 5 --dimensions AppName=myapp
Expected OutputExpected
No output (command runs silently)
--namespace - Defines the category for the custom metric
--metric-name - Names the custom metric
--value - Sets the metric's value
--dimensions - Adds extra info to identify the metric source
This command retrieves the sum of UserLogins custom metric values for the specified time range and app name.
Terminal
aws cloudwatch get-metric-statistics --namespace CustomApp --metric-name UserLogins --start-time 2024-06-01T00:00:00Z --end-time 2024-06-01T01:00:00Z --period 60 --statistics Sum --dimensions Name=AppName,Value=myapp
Expected OutputExpected
{ "Label": "UserLogins", "Datapoints": [ { "Timestamp": "2024-06-01T00:00:00Z", "Sum": 5.0, "Unit": "Count" } ] }
--start-time - Sets the beginning of the time range
--end-time - Sets the end of the time range
--period - Defines the granularity in seconds
--statistics - Chooses the type of statistic to retrieve
Key Concept

If you remember nothing else from this pattern, remember: default metrics track common resource data automatically, while custom metrics let you track what matters most to your app.

Common Mistakes
Trying to send custom metrics without specifying a namespace
CloudWatch requires a namespace to organize metrics; missing it causes the command to fail
Always include the --namespace flag with a meaningful name when sending custom metrics
Using default metric names when trying to send custom data
Default metric names are reserved and cannot be overwritten by custom data
Choose unique metric names under your custom namespace to avoid conflicts
Not specifying dimensions when retrieving custom metrics
Dimensions help identify the exact metric; missing them can return no data or wrong data
Always include the correct dimensions when querying custom metrics
Summary
Use 'aws cloudwatch list-metrics' to see default metrics AWS collects automatically.
Send custom metrics with 'aws cloudwatch put-metric-data' including namespace, metric name, value, and dimensions.
Retrieve custom metric data using 'aws cloudwatch get-metric-statistics' with proper time range and dimensions.