I want to apply a CloudWatch alarm to instances as they are being created. The alarm should send a message to an email account when CPU usage drops below 10% for 1 full day. I believe the best way of achieving this is by using a User data script at the time of launching the instance.
相关问题
- How to generate 12 digit unique number in redshift
- Use awslogs with kubernetes 'natively'
- JQ: Select when attribute value exists in a bash a
- Assume/switch role in aws toolkit for eclipse 2.0
- 'no SavedModel bundles found!' on tensorfl
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- how many objects are returned by aws s3api list-ob
- AWS S3 in rails - how to set the s3_signature_vers
- Passthrough input to output in AWS Step Functions
- I cannot locate production log files on Elastic Be
- ImportError: cannot import name 'joblib' f
- Static IP for Auto Scale in AWS
- Step function exceeding the maximum number of char
John Rotenstein is correct. What is required is to create an SNS topic, subscribe to it, and create a CloudWatch alarm on "CPUUtilization" metric. In order to do this automatically, either these steps need to be executed at the time when a new instance is started, or baked-in into the base AMI from which new instances are launched!
You can refer to AwsWinSysOps for a quick-start guide to setting it up.
Yes, you could use User Data to create the CloudWatch Alarm and notification.
Start by creating an Amazon SNS topic for receiving notifications. Subscribe an email address to receive the notifications. This SNS topic can be used for all notifications, so only needs to be created once.
Then, create a User Data script to configure the alarm. I recommend using the AWS Command Line Interface (CLI). The example below assumes Linux, but you could do similar in Windows, especially PowerShell.
First, grab the InstanceId:
Then, create an alarm to trigger when CPU drops below 10%, measured on an hourly average, over a period of 24 hours:
The actual values might take some tweaking to get the results you desire.
Alternatively, you could just write a script that runs on the instance itself, monitors itself, and sends out an email without involving CloudWatch. Less moving parts!