Difference between revisions of "AWS::CloudWatch::Alarm"

From wikieduonline
Jump to navigation Jump to search
Line 2: Line 2:
  
 
*<code>[[AWS::CloudWatch::AnomalyDetector]]</code>
 
*<code>[[AWS::CloudWatch::AnomalyDetector]]</code>
 +
 +
===Autoscaling===
 +
<pre> AppScaleUpPolicy:
 +
    Type: AWS::AutoScaling::ScalingPolicy
 +
    Properties:
 +
      AdjustmentType: ChangeInCapacity
 +
      AutoScalingGroupName: !Ref DeployAppASG
 +
      Cooldown: '60'
 +
      ScalingAdjustment: 1</pre>
 +
 +
<pre>AppScaleDownPolicy:
 +
    Type: AWS::AutoScaling::ScalingPolicy
 +
    Properties:
 +
      AdjustmentType: ChangeInCapacity
 +
      AutoScalingGroupName: !Ref DeployAppASG
 +
      Cooldown: '300'
 +
      ScalingAdjustment: -1</pre>
 +
 +
===CPU alarm===
 +
<pre>CPUAlarmHigh:
 +
    Type: AWS::CloudWatch::Alarm
 +
    Properties:
 +
      AlarmDescription: Scale-up if CPU > 80% for 5 minutes
 +
      MetricName: CPUUtilization
 +
      Namespace: AWS/EC2
 +
      Statistic: Average
 +
      Period: 300
 +
      EvaluationPeriods: 2
 +
      Threshold: 80
 +
      AlarmActions: [!Ref AppScaleUpPolicy]
 +
      Dimensions:
 +
      - Name: AutoScalingGroupName
 +
        Value: !Ref DeployAppASG
 +
      ComparisonOperator: GreaterThanThreshold
 +
 +
  CPUAlarmLow:
 +
    Type: AWS::CloudWatch::Alarm
 +
    Properties:
 +
      AlarmDescription: Scale-down if CPU < 60% for 5 minutes
 +
      MetricName: CPUUtilization
 +
      Namespace: AWS/EC2
 +
      Statistic: Average
 +
      Period: 300
 +
      EvaluationPeriods: 2
 +
      Threshold: 80
 +
      AlarmActions: [!Ref AppScaleDownPolicy]
 +
      Dimensions:
 +
      - Name: AutoScalingGroupName
 +
        Value: !Ref DeployAppASG
 +
      ComparisonOperator: LessThanThreshold</pre>
 +
  
 
== See also ==
 
== See also ==

Revision as of 10:50, 27 September 2021

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html

Autoscaling

 AppScaleUpPolicy:
    Type: AWS::AutoScaling::ScalingPolicy
    Properties:
      AdjustmentType: ChangeInCapacity
      AutoScalingGroupName: !Ref DeployAppASG
      Cooldown: '60'
      ScalingAdjustment: 1
AppScaleDownPolicy:
    Type: AWS::AutoScaling::ScalingPolicy
    Properties:
      AdjustmentType: ChangeInCapacity
      AutoScalingGroupName: !Ref DeployAppASG
      Cooldown: '300'
      ScalingAdjustment: -1

CPU alarm

CPUAlarmHigh:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmDescription: Scale-up if CPU > 80% for 5 minutes
      MetricName: CPUUtilization
      Namespace: AWS/EC2
      Statistic: Average
      Period: 300
      EvaluationPeriods: 2
      Threshold: 80
      AlarmActions: [!Ref AppScaleUpPolicy]
      Dimensions:
      - Name: AutoScalingGroupName
        Value: !Ref DeployAppASG
      ComparisonOperator: GreaterThanThreshold

  CPUAlarmLow:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmDescription: Scale-down if CPU < 60% for 5 minutes
      MetricName: CPUUtilization
      Namespace: AWS/EC2
      Statistic: Average
      Period: 300
      EvaluationPeriods: 2
      Threshold: 80
      AlarmActions: [!Ref AppScaleDownPolicy]
      Dimensions:
      - Name: AutoScalingGroupName
        Value: !Ref DeployAppASG
      ComparisonOperator: LessThanThreshold


See also

Advertising: