Analyzing CloudWatch Metrics Service with Query Parameters
CWLI query language.1. Summarize CloudWatch Metrics API Calls
Understand the volume of different API calls within a given timeframe.
filter eventSource = 'monitoring.amazonaws.com'
| stats count(*) as CallCount by eventName as API
| sort CallCount desc
2. Summarize CloudWatch Metrics API Calls with Errors
Identify the top API's returning errors and provide additional context on the failure.
filter eventSource = 'monitoring.amazonaws.com' and ispresent(errorCode)
| stats count(*) as CallCount by eventName as API, errorCode, errorMessage
| sort CallCount desc
3. Summarize CloudWatch Metric API by Account ID
Identify AWS Account ID's and Source IP's with highest GetMetricData or PutMetricData usage. Default to PutMetricData.
"parameters": [
{
"name": "CW_Metrics_API",
"defaultValue": "PutMetricData",
"description": "CloudWatch Metric API (e.g. PutMetricData, GetMetricData)"
}
]
filter eventName = '{{CW_Metrics_API}}'
| stats count(*) as CallCount by userIdentity.accountId as Account_ID
| sort CallCount desc
4. Summarize CloudWatch Metric API by UserAgent & Client IP Address
Identify AWS Account ID's and Source IP's with highest GetMetricData or PutMetricData usage. Default to PutMetricData.
"parameters": [
{
"name": "CW_Metrics_API",
"defaultValue": "PutMetricData",
"description": "CloudWatch Metric API (e.g. PutMetricData, GetMetricData)"
}
]
filter eventName = '{{CW_Metrics_API}}'
| stats count(*) as CallCount by userAgent, sourceIPAddress as Client_IP
| sort CallCount desc
5. Summarize CloudWatch Metrics API calls by IAM Role or User
Identify IAM Role or User with highest GetMetricData and PutMetricData usage. Default to PutMetricData.
"parameters": [
{
"name": "CW_Metrics_API",
"defaultValue": "PutMetricData",
"description": "CloudWatch Metric API (e.g. PutMetricData, GetMetricData)"
}
]
filter eventName = '{{CW_Metrics_API}}'
| stats count(*) as CallCount by userIdentity.arn as IAM_Role_User
| sort CallCount desc
6. Summarize PutMetricData API calls by Account ID, Client IP Address & Namespace
Identify the Account ID's and Client IP addresses with the highest usage. To assist with isolating the relevant workloads, include Namespace details.
filter eventName = 'PutMetricData'
| stats count(*) as CallCount by userIdentity.accountId as Calling_Account_ID, sourceIPAddress as Client_IP, requestParameters.namespace as Namespace
| sort CallCount desc
7. Summarize PutMetricData API calls by ResourceType, Entity, Client IP & Namespace
Identify the AWS Service (e.g. EC2, EKS), resources (e.g EC2 instances), source IP addresses with the highest usage. To assist with isolating the relevant workloads, include Namespace details.
filter eventName = 'PutMetricData'
| stats count(*) as CallCount by requestParameters.entityMetricData.0.entity.keyAttributes.ResourceType as ResourceType, requestParameters.entityMetricData.0.entity.keyAttributes.Identifier as Entity, sourceIPAddress as Client_IP, requestParameters.namespace as Namespace
| sort CallCount desc
8. Timeseries: CloudWatch Metrics API calls by Day
Create a graph visualizing the volume of CloudWatch Metrics API calls per day. This is useful when analyzing API call volumes over a billing period.
"parameters": [
{
"name": "CW_Metrics_API",
"defaultValue": "PutMetricData",
"description": "CloudWatch Metric API (e.g. PutMetricData, GetMetricData)"
}
]
filter eventName = '{{CW_Metrics_API}}'
| stats count(*) as CallCount by bin(1d)
9. Timeseries: CloudWatch Metrics API calls by Second
Create a graph visualizing the volume of CloudWatch Metrics API calls issued by a specific IAM role ARN. By analyzing with per second granularity and consider current quotas, it becomes easier to review throttling.
"parameters": [
{
"name": "CW_Metrics_API",
"defaultValue": "PutMetricData",
"description": "CloudWatch Metric API (e.g. PutMetricData, GetMetricData)"
},
{
"name": "IAM_ARN",
"defaultValue": "arn:aws:sts::123456789012:assumed-role/Admin",
"description": "IAM Role issuing the CloudWatch Metrics API calls"
}
]
filter eventName = '{{CW_Metrics_API}}' and userIdentity.arn = '{{IAM_ARN}}'
| stats count(*) as CallCount by bin(1s)