cloudwatch alarmのテンプレートを記述したのですが、AWSの説明であんまり理解できなかったので半分覚え書きで書いています。
cloudwatch alarmのリファレンス: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html
困ったこと
- アラームの条件設定の対応がわからない
- カスタムメトリクスの書き方がわからない
- 各リソースのメトリクスの書き方がわからない
アラームの条件設定の対応がわからない
EvaluationPeriods
- 指定した [Threshold] の値とデータを比較する時間。
- Required: Yes
- Type: Integer
Period
- 指定した統計を適用する期間。60 の倍数で、時間を秒単位で指定します。
- Required: Yes
- Type: Integer
Threshold
- 指定した [Statistic] の値と比較する値。
- Required: Yes
- Type: Double
ComparisonOperator
- 指定した Statistic および Threshold を比較するときに使用する算術演算。AWS CloudFormation は、1 番目のオペランドとして Statistic の値を使用します。
- 次の値を指定できます。GreaterThanOrEqualToThreshold(以上)、GreaterThanThreshold(超える)、LessThanThreshold(未満)、LessThanOrEqualToThreshold(以下)。
- Required: Yes
- Type: String
[Period]分間に[Threshold]回[ComparisonOperator]の状態が[EvaluationPeriods]回続いたらアラートを出す
カスタムメトリクスの書き方がわからない
↓URLにかかれているとおり、filterを作って
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html
Dimensionsにarnを書く
各リソースのメトリクスの書き方がわからない
例としてElasticBeanstalkを出しますがS3、SQSなど必要に応じて書き換えてください
- DimensionsにはEBのarn
- MetricNameはURLのを
https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/monitoring/aeb-metricscollected.html
- Namespaceは"AWS/リソース名"
下記のように書けばアラームがメトリクスが使えます。
Dimensions:
-
Name: !Ref ElasticBeanstalkのarn
Value: !Ref ElasticBeanstalkのarn
MetricName: "ApplicationRequests5xx"
Namespace: "AWS/ElasticBeanstalk"