问题
I am trying to create a dashboard and want a widget to display the CPUUtilization graphs of ALL EC2 instances within my autoscaling. Whenever a new instance gets added by autoscaling rules then the dashboard widget should include the graph of new EC2 instance automatically and when an instance gets deleted it should remove the graph of that instance.
When I select the autoscaling group as the metric it simply displays one line in the graph although there are 4 instances within that autoscaling groups.
Is that possible? If yes, what am I doing wrong?
回答1:
AWS team release an Lambda function to auto update your dashboard : here is the link
The script:
- Loads the specified CloudWatch Dashboard(s)
- Looks for all graph widgets displaying EC2 instance metrics
- Calls EC2 DescribeInstances API with configured parameters to discover the current EC2 instances for that graph in that region
- Updates the widget if needed
- Saves the CloudWatch Dashboards if any widget definition has changed
But it have also limitation :
- it will only update graphs whose first metric is an EC2 instance metric, all other metrics on the graph will be replaced with these metrics
- metrics can not have custom periods or statistics, the graph defaults will be used
回答2:
A copy paste from this other question
Better late than never, it seems that CloudWatch has implemented a SEARCH
function with metric expressions.
There are good examples in the documentation:
SEARCH(' {AWS/EC2,InstanceId} MetricName="CPUUtilization" ', 'Average', 300)
回答3:
Auto scaling groups in AWS are based on Launch configurations, which contain a monitoring
tickbox.
If you enable this box, each instance added to the ASG would be launched with Cloudwatch monitoring.
Once you make sure this box is ticked, you can find a way to load the alerts on the new instances joining the group individually to the dashboard.
来源:https://stackoverflow.com/questions/39743459/dynamically-adding-removing-ec2-instances-of-an-autoscalinggroup-to-aws-dashboar