Skip to content

Instantly share code, notes, and snippets.

@csereno
Last active July 30, 2023 19:44
Show Gist options
  • Save csereno/2c22d526318c61ebf9d3e9bf2dbd5141 to your computer and use it in GitHub Desktop.
Save csereno/2c22d526318c61ebf9d3e9bf2dbd5141 to your computer and use it in GitHub Desktop.
AWS CloudWatch EC2 Alarms
Reference: https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/put-metric-alarm.html
===HIGH CPU===
aws cloudwatch put-metric-alarm --alarm-name "High CPU Util on INSTANCE" --alarm-description "Alarm when CPU exceeds 90 percent" --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 300 --threshold 90 --comparison-operator GreaterThanThreshold --dimensions "Name=InstanceId,Value=INSTANCE" --evaluation-periods 2 --alarm-actions "arn:aws:sns:REGION:ACCOUNT:SNSTOPIC" --unit Percent
===HIGH MEM===
aws cloudwatch put-metric-alarm --alarm-name "High Memory Util on INSTANCE" --alarm-description "Alarm when Memory exceeds 90 percent" --metric-name mem_used_percent --namespace AWS/EC2 --statistic Average --period 300 --threshold 90 --comparison-operator GreaterThanThreshold --dimensions "Name=InstanceId,Value=INSTANCEID" --evaluation-periods 2 --alarm-actions "arn:aws:sns:REGION:ACCOUNT:SNSTOPIC" --unit Percent
===StatusCheckFailed===
aws cloudwatch put-metric-alarm --alarm-name "EC2 Status Check Failed --alarm-description "An EC2 Status Check Failed" --metric-name StatusCheckFailed --namespace AWS/EC2 --statistic Maximum --period 60 --unit Count --evaluation-periods 2 --threshold 1 --comparison-operator GreaterThanOrEqualToThreshold --dimensions "Name=InstanceID,Value=INSTANCEID" --treat-missing-data missing --alarm-actions "arn:aws:sns:REGION:ACCOUNT:SNSTOPIC"
===SystemStatusCheckFailed===
aws cloudwatch put-metric-alarm --alarm-name "System Status Check Failed" --alarm-description "An EC2 System Status Check Failed" --metric-name StatusCheckFailed_System --namespace AWS/EC2 --statistic Maximum --period 60 --unit Count --evaluation-periods 2 --threshold 1 --comparison-operator GreaterThanOrEqualToThreshold --dimensions "Name=InstanceID,Value=INSTANCEID" --treat-missing-data missing --alarm-actions "arn:aws:sns:REGION:ACCOUNT:SNSTOPIC"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment