Collector "AWS-CloudWatch" Configuration Manual¶
Before reading this document, please read:
Tip
Before using this collector, you must install "Integration Core" and its accompanying third-party dependencies.
Tip
This collector supports multi-threading by default (five threads are enabled by default). If you need to change the thread pool size, you can set the environment variable COLLECTOR_THREAD_POOL_SIZE.
1. Configuration Structure¶
The configuration structure of this collector is as follows:
| Field | Type | Required | Description |
|---|---|---|---|
Regions |
List | Required | List of CloudWatch regions to collect |
regions[#] |
str | Required | Region ID, e.g., 'ap-southeast-1'See the appendix for the complete list |
targets |
list | Required | List of CloudWatch target configurations Multiple configurations under the same namespace have a logical "AND" relationship |
targets[#].namespace |
str | Required | CloudWatch namespace to collect, e.g., 'AWS/EC2'. See the appendix for the complete list |
targets[#].dimensions |
str | Optional | List of CloudWatch dimension names to collect. This is a new configuration that specifies the dimensions of the collected metrics See the appendix for the complete list |
targets[#].metrics |
list | Required | List of CloudWatch metric names to collect See the appendix for the complete list |
targets[#].metrics[#] |
str | Required | Metric name pattern, supports "NOT", wildcard matchingNormally, multiple patterns have a logical "OR" relationship. When "NOT" is included, multiple patterns have a logical "AND" relationship. See below for details |
2. Configuration Examples¶
Specifying Specific Metrics¶
Collect the CPUCreditBalance and MetadataNoToken metrics from the AWS/EC2 namespace with the InstanceId dimension.
aws_cloudwatch_configs = {
'regions': ['ap-southeast-1'],
'targets': [
{
'namespace' : 'AWS/EC2',
'dimensions': ['InstanceId'],
'metrics' : ['CPUCreditBalance', 'MetadataNoToken'],
}
],
}
Wildcard Matching for Metrics¶
Metric names can use the * wildcard for matching.
In this example, the following metrics will be collected:
-
Metrics with the
InstanceIddimension -
Metrics named
CPUCreditBalance -
Metrics starting with
CPU -
Metrics ending with
Balance -
Metrics containing
Credit
aws_cloudwatch_configs = {
'regions': ['ap-southeast-1'],
'targets': [
{
'namespace' : 'AWS/EC2',
'dimensions': ['InstanceId'],
'metrics' : ['CPUCreditBalance', 'CPU*', '*Balance', '*Credit*'],
}
],
}
Excluding Specific Metrics¶
Adding the "NOT" marker at the beginning indicates that the following metrics should be excluded.
In this example, the following metrics will [not] be collected:
-
Metrics with the
InstanceIddimension -
Metrics named
CPUCreditBalance -
Metrics starting with
CPU -
Metrics ending with
Balance -
Metrics containing
Credit
aws_cloudwatch_configs = {
'regions': ['ap-southeast-1'],
'targets': [
{
'namespace' : 'AWS/EC2',
'dimensions': ['InstanceId'],
'metrics' : ['NOT', 'CPUCreditBalance', 'CPU*', '*Balance', '*Credit*'],
}
],
}
Multi-step Filtering for Specific Metrics¶
The same namespace can be specified multiple times, with metrics filtered step-by-step from top to bottom.
In this example, the metric names are filtered as follows:
-
All metrics containing
CPUin theInstanceIddimension -
From the previous result, exclude the metric named
CPUUtilization
aws_cloudwatch_configs = {
'regions': ['ap-southeast-1'],
'targets': [
{
'namespace' : 'AWS/EC2',
'dimensions': ['InstanceId'],
'metrics' : ['*CPU*'],
},
{
'namespace' : 'AWS/EC2',
'dimensions': ['InstanceId'],
'metrics' : ['NOT', 'CPUCreditBalance'],
},
],
}
Configuring Filters (Optional)¶
This collector script supports custom filters, allowing users to filter target resources based on object attributes. The filter function returns True or False.
- True: The target resource should be collected.
- False: The target resource should not be collected.
# Example: Enabling a filter to filter based on RegionId and InstanceId attributes. Configuration format is as follows:
def filter_instance(instance, namespace='AWS/EC2'):
'''
Collect metrics for InstanceId i-0d7620xxxxxxxa, i-0d7620xxxxxxxb and RegionId ap-southeast-1
'''
region_id = instance['tags'].get('RegionId')
instance_id = instance['tags'].get('InstanceId')
if instance_id in ['i-0d7620xxxxxxxa', 'i-0d7620xxxxxxxb'] and region_id in ['ap-southeast-1']:
return True
return False
from integration_core__runner import Runner
import integration_aws_cloudwatch__main as main
@DFF.API('AWS-CloudWatch Collection', timeout=3600, fixed_crontab='*/15 * * * *')
def run():
Runner(main.DataCollector(account, collector_configs, filters=[filter_instance])).run()
Tip
When configuring multiple filters under the same namespace, all filters must be satisfied for the data to be reported.
3. Data Collection Details¶
Cloud Product Configuration Information¶
| Product Name | Namespace (Namespace) | Dimension (Dimension) | Description |
|---|---|---|---|
Amazon EC2 |
AWS/EC2 |
InstanceId |
|
Amazon RDS |
AWS/RDS |
DBInstanceIdentifier |
|
Amazon S3 |
AWS/S3 |
* |
* means collecting all dimensions under this namespace, same below S3 request metrics require manual configuration in the console, see the appendix for details |
Amazon OpenSearch Service |
AWS/ES |
* |
Same as above |
Elastic Load Balancing |
AWS/ELB |
LoadBalancerName |
|
Elastic Load Balancing |
AWS/NetworkELBAWS/GatewayELBAWS/ApplicationELB |
LoadBalancer |
Filter metric data by load balancer. Specify the load balancer as follows: net/load-balancer-name/1234567890123456 (the end part of the load balancer ARN). |
Amazon ElastiCache for Memcached |
AWS/ElastiCache |
CacheClusterId |
The collector currently collects host-level metrics, see the appendix for details (Amazon ElastiCache for Memcached host-level metric monitoring) |
Amazon ElastiCache for Redis |
AWS/ElastiCache |
CacheClusterId |
The collector currently collects host-level metrics, see the appendix for details (Amazon ElastiCache for Redis host-level metric monitoring) |
4. Data Reporting Format¶
After data is successfully synchronized, you can view the data in the "Metrics" section of Guance.
Take the following collector configuration as an example:
aws_cloudwatch_configs = {
'regions': ['ap-southeast-1'],
'targets': [
{
'namespace' : 'AWS/EC2',
'dimensions': ['InstanceId'],
'metrics' : ['CPUCreditBalance'],
},
],
}
The reported data example is as follows:
{
"measurement": "aws_AWS/EC2",
"tags": {
"Dimensions": "InstanceId",
"InstanceId": "i-xxx"
},
"fields": {
"CPUCreditBalance_Average" : 576.0,
"CPUCreditBalance_Maximum" : 576.0,
"CPUCreditBalance_Minimum" : 576.0,
"CPUCreditBalance_SampleCount": 1.0,
"CPUCreditBalance_Sum" : 576.0
}
}
Tip
All metric values will be reported as float type.
Tip
This collector collects data from the AWS/EC2 namespace with the InstanceId dimension. See Data Collection Details for more information.
5. Interaction with Custom Object Collectors¶
When other custom object collectors (e.g., EC2) are running in the same DataFlux Func, this collector will collect based on the dimensions specified in Data Collection Details. For example, fields like tags.InstanceId will attempt to match the tags.name field in the custom object.
Instance-level metrics are automatically supplemented. For an explanation of instance dimensions, refer to Data Collection Details.
Since custom object information needs to be obtained first for the CloudWatch collector to interact, it is generally recommended to place the CloudWatch collector at the end of the list, e.g.:
# Create collectors
collectors = [
aws_ec2.DataCollector(account, common_aws_configs),
aws_cloudwatch.DataCollector(account, aws_cloudwatch_configs) # CloudWatch collector is usually placed last
]
When a match is successful, additional fields from the custom object tags will be added to the CloudWatch data tags, enabling effects like filtering CloudWatch metrics by instance name. The specific effect is as follows:
Assume the original data collected by CloudWatch is as follows:
{
"measurement": "aws_AWS/EC2",
"tags": {
"Dimensions": "InstanceId",
"InstanceId": "i-xxx"
},
"fields": { "Content omitted" }
},
Meanwhile, the custom object data collected by the AWS EC2 collector is as follows:
{
"measurement": "aws_ec2",
"tags": {
"InstanceType" : "c6g.xxx",
"PlatformDetails": "xxx",
"{key}" : "{value}"
},
"fields": { "Content omitted" }
}
Then, the final CloudWatch data reported will be as follows:
{
"measurement": "aws_AWS/EC2",
"tags": {
"InstanceId" : "i-xxx", // Original CloudWatch field
"Dimensions" : "InstanceId", // Dimension information field
"InstanceType" : "c6g.xxx", // Field from custom object EC2
"PlatformDetails" : "xxx", // Field from custom object EC2
"{key}" : "{value}"
},
"fields": { "Content omitted" }
},
6. Cloud Monitoring Call Costs¶
AWS CloudWatch charges for API calls to retrieve metrics. Refer to Amazon (Global) CloudWatch Pricing, Amazon (China) CloudWatch Pricing. The GetMetricData and ListMetrics APIs used by this collector are within the scope of charges.
Note that GetMetricData is not charged based on the number of API requests but on the number of metric requests. Therefore, the number of API requests is not a reference. For definitions related to metric requests, please refer to the AWS pricing documentation.
7. IAM Policy Permissions¶
Note
If users use IAM roles to collect resources, certain operation permissions need to be enabled.
This collector requires the following operation permissions:
cloudwatch:GetMetricData
cloudwatch:ListMetrics
Notes¶
Error Scenarios and Solutions for Triggered Tasks¶
HTTPClientError: An HTTP Client raised an unhandled exception: SoftTimeLimitExceeded()
Reason: The task execution time is too long, causing a timeout.
Solution:
-
Increase the timeout setting for the task appropriately (e.g.,
@DFF.API('Execute Collection', timeout=120, fixed_crontab="* * * * *"), which sets the timeout to 120 seconds). -
About CloudWatch Agent Collecting Metrics from Amazon EC2 Instances and On-premises Servers
Reason: The agent collects metrics from Amazon EC2 instances and on-premises servers.
Solution: - https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html
X. Appendix¶
AWS CloudWatch¶
Refer to AWS official documentation:
- Regions and Availability Zones
- S3 Using Amazon CloudWatch Monitoring Metrics
- AWS Services in CloudWatch Namespaces
- CloudWatch Viewing Available Metrics and Dimensions
- Amazon ElastiCache for Memcached Host-Level Metric Monitoring
- Amazon ElastiCache for Redis Host-Level Metric Monitoring
- Amazon (Global) CloudWatch Pricing
- Amazon (China) CloudWatch Pricing