@@ -25,23 +25,26 @@ export class EventMonitoring extends Construct {
2525 super ( scope , id ) ;
2626
2727 // Create alarms on API Gateway
28- props ?. producer . api . metricClientError ( ) . createAlarm ( scope , 'HighClientErrorAlarm' , {
28+ const clientErrorAlarm = props ?. producer . api . metricClientError ( ) . createAlarm ( scope , 'HighClientErrorAlarm' , {
2929 evaluationPeriods : 3 ,
3030 threshold : 20 ,
3131 alarmDescription : 'Alert when client error rate exceeds 20%'
3232 } ) ;
33+ this . alarms . push ( clientErrorAlarm ! ) ;
3334
34- props ?. producer . api . metricServerError ( ) . createAlarm ( scope , 'HighServerErrorAlarm' , {
35+ const serverErrorAlarm = props ?. producer . api . metricServerError ( ) . createAlarm ( scope , 'HighServerErrorAlarm' , {
3536 evaluationPeriods : 3 ,
3637 threshold : 1 ,
3738 alarmDescription : 'Alert when server error rate exceeds 1%'
3839 } ) ;
40+ this . alarms . push ( serverErrorAlarm ! ) ;
3941
40- props ?. producer . api . metricLatency ( ) . createAlarm ( scope , 'HighLatencyAlarm' , {
42+ const latencyAlarm = props ?. producer . api . metricLatency ( ) . createAlarm ( scope , 'HighLatencyAlarm' , {
4143 evaluationPeriods : 3 ,
4244 threshold : 1000 ,
4345 alarmDescription : 'Alert when latency exceeds 1 second'
4446 } ) ;
47+ this . alarms . push ( latencyAlarm ! ) ;
4548
4649 // Create metrics on EventBridge Bus
4750 const busInvocations = new Metric ( {
@@ -65,14 +68,15 @@ export class EventMonitoring extends Construct {
6568 } ) ;
6669
6770 // Create alarms on EventBridge Bus
68- new Alarm ( this , 'EventBusFailedInvocationsAlarm' , {
71+ const busFailedInvocationsAlarm = new Alarm ( this , 'EventBusFailedInvocationsAlarm' , {
6972 metric : busFailedInvocations ,
7073 threshold : 1 ,
7174 evaluationPeriods : 3 ,
7275 datapointsToAlarm : 2 ,
7376 alarmDescription : 'Alert when EventBridge bus has failed invocations' ,
7477 treatMissingData : TreatMissingData . NOT_BREACHING
7578 } ) ;
79+ this . alarms . push ( busFailedInvocationsAlarm ) ;
7680
7781 // For each rule, create metrics and alarms
7882 props ?. router . rules ?. forEach ( ( rule , index ) => {
@@ -107,81 +111,87 @@ export class EventMonitoring extends Construct {
107111 } ) ;
108112
109113 // Rule Failed Invocations Alarm
110- new Alarm ( this , `RuleFailedInvocationsAlarm-${ index } ` , {
114+ const ruleFailedInvocationsAlarm = new Alarm ( this , `RuleFailedInvocationsAlarm-${ index } ` , {
111115 metric : ruleFailedInvocations ,
112116 threshold : 1 ,
113117 evaluationPeriods : 2 ,
114118 datapointsToAlarm : 2 ,
115119 alarmDescription : `Alert when EventBridge rule ${ rule . ruleName } has failed invocations` ,
116120 treatMissingData : TreatMissingData . NOT_BREACHING
117121 } ) ;
122+ this . alarms . push ( ruleFailedInvocationsAlarm ) ;
118123
119124 // Rule Throttled Events Alarm
120- new Alarm ( this , `RuleThrottledEventsAlarm-${ index } ` , {
125+ const ruleThrottledEventsAlarm = new Alarm ( this , `RuleThrottledEventsAlarm-${ index } ` , {
121126 metric : ruleThrottledRules ,
122127 threshold : 1 ,
123128 evaluationPeriods : 1 ,
124129 alarmDescription : `Alert when EventBridge rule ${ rule . ruleName } is being throttled` ,
125130 treatMissingData : TreatMissingData . NOT_BREACHING
126131 } ) ;
132+ this . alarms . push ( ruleThrottledEventsAlarm ) ;
127133 } ) ;
128134
129135 // Create alarms for SNS topics
130136 props ?. router . topics ?. forEach ( ( topic , index ) => {
131137 const topicNumberOfNotificationsFailed = topic . metricNumberOfNotificationsFailed ( ) ;
132138
133- new Alarm ( this , `TopicFailedNotificationsAlarm-${ index } ` , {
139+ const topicFailedNotificationsAlarm = new Alarm ( this , `TopicFailedNotificationsAlarm-${ index } ` , {
134140 threshold : 1 ,
135141 evaluationPeriods : 1 ,
136142 alarmDescription : `Alert when any notifications fail to deliver for topic ${ topic . topicName } ` ,
137143 comparisonOperator : cdk . aws_cloudwatch . ComparisonOperator . GREATER_THAN_THRESHOLD ,
138144 metric : topicNumberOfNotificationsFailed
139145 } ) ;
146+ this . alarms . push ( topicFailedNotificationsAlarm ) ;
140147 } ) ;
141148
142149 // Create alarms for Consumer SQS queues
143150 props ?. consumers ?. forEach ( ( consumer , index ) => {
144151 const queueApproximateNumberOfMessagesVisible = consumer . queue . metricApproximateNumberOfMessagesVisible ( ) ;
145152
146- new Alarm ( this , `QueueApproximateNumberOfMessagesVisibleAlarm-${ index } ` , {
153+ const queueMessagesVisibleAlarm = new Alarm ( this , `QueueApproximateNumberOfMessagesVisibleAlarm-${ index } ` , {
147154 threshold : 100 ,
148155 evaluationPeriods : 1 ,
149156 alarmDescription : `Alert when the approximate number of messages visible in the queue ${ consumer . queue . queueName } exceeds 100` ,
150157 comparisonOperator : cdk . aws_cloudwatch . ComparisonOperator . GREATER_THAN_THRESHOLD ,
151158 metric : queueApproximateNumberOfMessagesVisible
152159 } ) ;
160+ this . alarms . push ( queueMessagesVisibleAlarm ) ;
153161
154162 const queueApproximateAgeOfOldestMessage = consumer . queue . metricApproximateAgeOfOldestMessage ( ) ;
155- new Alarm ( this , `QueueApproximateAgeOfOldestMessageAlarm-${ index } ` , {
163+ const queueOldestMessageAlarm = new Alarm ( this , `QueueApproximateAgeOfOldestMessageAlarm-${ index } ` , {
156164 threshold : 900 ,
157165 evaluationPeriods : 1 ,
158166 alarmDescription : `Alert when the approximate age of the oldest message in the queue ${ consumer . queue . queueName } exceeds 900 seconds` ,
159167 comparisonOperator : cdk . aws_cloudwatch . ComparisonOperator . GREATER_THAN_THRESHOLD ,
160168 metric : queueApproximateAgeOfOldestMessage
161169 } ) ;
170+ this . alarms . push ( queueOldestMessageAlarm ) ;
162171 } ) ;
163172
164173 // Create alarms on Dead Letter Queues
165174 props ?. deadLetterQueues . forEach ( ( queue , index ) => {
166175 const queueApproximateNumberOfMessagesVisible = queue . metricApproximateNumberOfMessagesVisible ( ) ;
167176
168- new Alarm ( this , `DeadLetterQueueApproximateNumberOfMessagesVisibleAlarm-${ index } ` , {
177+ const dlqMessagesVisibleAlarm = new Alarm ( this , `DeadLetterQueueApproximateNumberOfMessagesVisibleAlarm-${ index } ` , {
169178 threshold : 1 ,
170179 evaluationPeriods : 1 ,
171180 alarmDescription : `Alert when the approximate number of messages visible in the dead letter queue ${ queue . queueName } exceeds 1` ,
172181 comparisonOperator : cdk . aws_cloudwatch . ComparisonOperator . GREATER_THAN_THRESHOLD ,
173182 metric : queueApproximateNumberOfMessagesVisible
174183 } ) ;
184+ this . alarms . push ( dlqMessagesVisibleAlarm ) ;
175185
176- // make an alarm on the age of the oldest message > 1 day
177186 const queueApproximateAgeOfOldestMessage = queue . metricApproximateAgeOfOldestMessage ( ) ;
178- new Alarm ( this , `DeadLetterQueueApproximateAgeOfOldestMessageAlarm-${ index } ` , {
187+ const dlqOldestMessageAlarm = new Alarm ( this , `DeadLetterQueueApproximateAgeOfOldestMessageAlarm-${ index } ` , {
179188 threshold : 86400 ,
180189 evaluationPeriods : 1 ,
181190 alarmDescription : `Alert when the approximate age of the oldest message in the dead letter queue ${ queue . queueName } exceeds 1 day` ,
182191 comparisonOperator : cdk . aws_cloudwatch . ComparisonOperator . GREATER_THAN_THRESHOLD ,
183192 metric : queueApproximateAgeOfOldestMessage
184193 } ) ;
194+ this . alarms . push ( dlqOldestMessageAlarm ) ;
185195 } ) ;
186196
187197 // Create a new dashboard
0 commit comments