CloudWatchAlarmでlinuxとwindowsでMetricMathの計算方法が異なるため条件分岐させる方法
'''
Parameters:
PlatformType:
Type: String
AllowedValues:
- Linux
- Windows
Default: Linux
Description: "The platform type (Linux or Windows)"
Resources:
PlatformSpecificAlarm:
Type: "AWS::CloudWatch::Alarm"
Properties:
AlarmName: "Platform-Specific-Replica-Ratio-Alarm"
AlarmDescription: "Triggers when the replica ratio falls below threshold, based on the platform type."
Metrics:
# Linux用メトリクス
- !If
- IsLinux
- Id: replicasReadyLinux
MetricStat:
Metric:
Namespace: "Kubernetes/ContainerInsights"
MetricName: "replicas_ready"
Dimensions:
- Name: ClusterName
Value: !Ref EKSClusterName
- Name: Namespace
Value: "my-namespace"
Period: 60
Stat: "Average"
ReturnData: false
# Windows用メトリクス
- !If
- IsWindows
- Id: replicasReadyWindows
MetricStat:
Metric:
Namespace: "AWS/Windows"
MetricName: "windows_replica_ready"
Dimensions:
- Name: ClusterName
Value: !Ref EKSClusterName
- Name: Namespace
Value: "my-namespace"
Period: 60
Stat: "Average"
ReturnData: false
- Id: replicasDesired
MetricStat:
Metric:
Namespace: "Kubernetes/ContainerInsights"
MetricName: "replicas_desired"
Dimensions:
- Name: ClusterName
Value: !Ref EKSClusterName
- Name: Namespace
Value: "my-namespace"
Period: 60
Stat: "Average"
ReturnData: false
- Id: replicaRatio
Expression: "replicasReady / replicasDesired * 100"
Label: "Replica Ratio (%)"
ReturnData: true
EvaluationPeriods: 1
Threshold: 90
ComparisonOperator: "LessThanThreshold"
TreatMissingData: "breaching"
Conditions:
IsLinux: !Equals [ !Ref PlatformType, "Linux" ]
IsWindows: !Equals [ !Ref PlatformType, "Windows" ]
'''