Last active
November 8, 2021 00:42
-
-
Save it-am/11fd32366dca75e8b59001e6aa4bba33 to your computer and use it in GitHub Desktop.
cloudformation-linux-cloudwatch-alarms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Description: Linux CloudWatch Alarms - CPU Memory Instance and System Status | |
#------------------------------------------------------------------------------ | |
Parameters: | |
#------------------------------------------------------------------------------ | |
instanceid: | |
Description: "Choose an instance id" | |
Type: AWS::EC2::Instance::Id | |
instancename: | |
Description: "Please provide EC2 instance name" | |
Type: "String" | |
MinLength: '1' | |
MaxLength: '50' | |
criticalsnsarn: | |
Description: "Please provide an ARN of SNS topic - CRITICAL Type" | |
Type: "String" | |
warningsnsarn: | |
Description: "Please provide an ARN of SNS topic - WARNING Type" | |
Type: "String" | |
#------------------------------------------------------------------------------ | |
Resources: | |
#------------------------------------------------------------------------------ | |
CPUAlarmWARNING: | |
Type: AWS::CloudWatch::Alarm | |
DeletionPolicy: Retain | |
Properties: | |
AlarmDescription: !Sub "${instancename} - ${instanceid} - High CPU Usage 90%" | |
AlarmActions: | |
- !Ref warningsnsarn | |
OKActions: | |
- !Ref warningsnsarn | |
MetricName: CPUUtilization | |
Namespace: AWS/EC2 | |
Statistic: Average | |
Period: '900' | |
EvaluationPeriods: '1' | |
Threshold: '90' | |
ComparisonOperator: GreaterThanOrEqualToThreshold | |
Dimensions: | |
- Name: InstanceId | |
Value: !Ref instanceid | |
#------------------------------------------------------------------------------ | |
CPUAlarmCRITICAL: | |
Type: AWS::CloudWatch::Alarm | |
DeletionPolicy: Retain | |
Properties: | |
AlarmDescription: !Sub "${instancename} - ${instanceid} - High CPU Usage 95%" | |
AlarmActions: | |
- !Ref criticalsnsarn | |
OKActions: | |
- !Ref criticalsnsarn | |
MetricName: CPUUtilization | |
Namespace: AWS/EC2 | |
Statistic: Average | |
Period: '900' | |
EvaluationPeriods: '2' | |
Threshold: '95' | |
ComparisonOperator: GreaterThanOrEqualToThreshold | |
Dimensions: | |
- Name: InstanceId | |
Value: !Ref instanceid | |
#------------------------------------------------------------------------------ | |
MemoryAlarmWARNING: | |
Type: AWS::CloudWatch::Alarm | |
DeletionPolicy: Retain | |
Properties: | |
AlarmDescription: !Sub "${instancename} - ${instanceid} - High Memory Usage 90%" | |
AlarmActions: | |
- !Ref warningsnsarn | |
OKActions: | |
- !Ref warningsnsarn | |
MetricName: "mem_used_percent" | |
Namespace: CWAgent | |
Statistic: Average | |
Period: '900' | |
EvaluationPeriods: '1' | |
Threshold: '90' | |
ComparisonOperator: GreaterThanOrEqualToThreshold | |
Dimensions: | |
- Name: InstanceId | |
Value: !Ref instanceid | |
#------------------------------------------------------------------------------ | |
MemoryAlarmCRITICAL: | |
Type: AWS::CloudWatch::Alarm | |
DeletionPolicy: Retain | |
Properties: | |
AlarmDescription: !Sub "${instancename} - ${instanceid} - High Memory Usage 95%" | |
AlarmActions: | |
- !Ref criticalsnsarn | |
OKActions: | |
- !Ref criticalsnsarn | |
MetricName: "mem_used_percent" | |
Namespace: CWAgent | |
Statistic: Average | |
Period: '900' | |
EvaluationPeriods: '2' | |
Threshold: '95' | |
ComparisonOperator: GreaterThanOrEqualToThreshold | |
Dimensions: | |
- Name: InstanceId | |
Value: !Ref instanceid | |
#------------------------------------------------------------------------------ | |
SystemStatusAlarmCRITICAL: | |
Type: AWS::CloudWatch::Alarm | |
DeletionPolicy: Retain | |
Properties: | |
AlarmDescription: !Sub "${instancename} - ${instanceid} - instance recovery process has been triggered because of failed System Status Check" | |
Namespace: AWS/EC2 | |
MetricName: StatusCheckFailed_System | |
Statistic: Minimum | |
Period: '60' | |
EvaluationPeriods: '2' | |
ComparisonOperator: GreaterThanThreshold | |
Threshold: '0' | |
AlarmActions: | |
- !Sub "arn:aws:automate:${AWS::Region}:ec2:recover" | |
- !Ref warningsnsarn | |
OKActions: | |
- !Ref warningsnsarn | |
Dimensions: | |
- Name: InstanceId | |
Value: !Ref instanceid | |
#------------------------------------------------------------------------------ | |
InstanceStatusAlarmCRITICAL: | |
Type: AWS::CloudWatch::Alarm | |
DeletionPolicy: Retain | |
Properties: | |
AlarmDescription: !Sub "${instancename} - ${instanceid} - Instance Status Check Failed - please investigate. Troubleshooting: https://goo.gl/Ea27Gd" | |
Namespace: AWS/EC2 | |
MetricName: StatusCheckFailed_Instance | |
Statistic: Minimum | |
Period: '60' | |
EvaluationPeriods: '3' | |
ComparisonOperator: GreaterThanThreshold | |
Threshold: '0' | |
AlarmActions: | |
- !Ref criticalsnsarn | |
OKActions: | |
- !Ref criticalsnsarn | |
Dimensions: | |
- Name: InstanceId | |
Value: !Ref instanceid | |
#----------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please assist me