Created
November 7, 2018 04:26
-
-
Save it-am/0c176bfba6b0dc567f6ee33dc2ccdb0e to your computer and use it in GitHub Desktop.
cloudformation-linux-cloudwatch-diskspace-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 Diskspace Alarms | |
#------------------------------------------------------------------------------ | |
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" | |
volume: | |
Description: "Provide disk's/folder's name (ex.: xvda1)" | |
Type: "String" | |
Default: "xvda1" | |
path: | |
Description: "Provide path" | |
Type: "String" | |
Default: "/" | |
fstype: | |
Description: "Choose fstype - ext4 or xfs -> Ubuntu and AmazonLinux use ext4, CentOS use xfs" | |
Type: String | |
AllowedValues: | |
- ext4 | |
- xfs | |
- btrfs | |
ConstraintDescription: You must specify ext4,xfs,or btrfs. | |
#------------------------------------------------------------------------------- | |
Resources: | |
#------------------------------------------------------------------------------- | |
DiskSpaceAlarmWARNING: | |
Type: AWS::CloudWatch::Alarm | |
DeletionPolicy: Retain | |
Properties: | |
AlarmDescription: !Sub "${instancename} - ${instanceid} - over 90% of ${volume} volume space is in use" | |
AlarmActions: | |
- !Ref warningsnsarn | |
OKActions: | |
- !Ref warningsnsarn | |
MetricName: "disk_used_percent" | |
Namespace: CWAgent | |
Statistic: Average | |
Period: '300' | |
EvaluationPeriods: '1' | |
Threshold: '90' | |
ComparisonOperator: GreaterThanOrEqualToThreshold | |
Dimensions: | |
- Name: InstanceId | |
Value: !Ref instanceid | |
- Name: device | |
Value: !Ref volume | |
- Name: path | |
Value: !Ref path | |
- Name: fstype | |
Value: !Ref fstype | |
#------------------------------------------------------------------------------- | |
DiskSpaceAlarmCRITICAL: | |
Type: AWS::CloudWatch::Alarm | |
DeletionPolicy: Retain | |
Properties: | |
AlarmDescription: !Sub "${instancename} - ${instanceid} - over 95% of ${volume} volume space is in use" | |
AlarmActions: | |
- !Ref criticalsnsarn | |
OKActions: | |
- !Ref criticalsnsarn | |
MetricName: "disk_used_percent" | |
Namespace: CWAgent | |
Statistic: Average | |
Period: '300' | |
EvaluationPeriods: '1' | |
Threshold: '95' | |
ComparisonOperator: GreaterThanOrEqualToThreshold | |
Dimensions: | |
- Name: InstanceId | |
Value: !Ref instanceid | |
- Name: device | |
Value: !Ref volume | |
- Name: path | |
Value: !Ref path | |
- Name: fstype | |
Value: !Ref fstype | |
#------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment