Skip to content

Commit ef896bd

Browse files
committed
feat: Create dashboard
1 parent 648bd9f commit ef896bd

File tree

1 file changed

+135
-1
lines changed

1 file changed

+135
-1
lines changed

lib/eventMonitoring.ts

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Construct } from 'constructs';
33
import { EventRouter } from './eventRouter';
44
import { EventProducer } from './eventProducer';
55
import { EventConsumer } from './eventConsumer';
6-
import { Alarm, Metric, TreatMissingData } from 'aws-cdk-lib/aws-cloudwatch';
6+
import { Alarm, Dashboard, GraphWidget, Metric, TextWidget, TreatMissingData } from 'aws-cdk-lib/aws-cloudwatch';
77
import { Queue } from 'aws-cdk-lib/aws-sqs';
88

99
export interface EventMonitoringProps {
@@ -179,5 +179,139 @@ export class EventMonitoring extends Construct {
179179
metric: queueApproximateAgeOfOldestMessage
180180
});
181181
});
182+
183+
// Create a new dashboard
184+
const dashboard = new Dashboard(this, 'EventMonitoringDashboard', {
185+
dashboardName: `${id}-monitoring-dashboard`
186+
});
187+
188+
// Add a title
189+
dashboard.addWidgets(new TextWidget({
190+
markdown: '# Event-Driven Architecture Monitoring',
191+
width: 24,
192+
height: 1
193+
}));
194+
195+
// API Gateway metrics
196+
dashboard.addWidgets(
197+
new GraphWidget({
198+
title: 'API Gateway Metrics',
199+
width: 12,
200+
height: 6,
201+
left: [
202+
props?.producer.api.metricClientError()!,
203+
props?.producer.api.metricServerError()!,
204+
],
205+
right: [
206+
props?.producer.api.metricLatency()!
207+
]
208+
})
209+
);
210+
211+
// EventBridge Bus metrics
212+
dashboard.addWidgets(
213+
new GraphWidget({
214+
title: 'EventBridge Bus Metrics',
215+
width: 12,
216+
height: 6,
217+
left: [
218+
busInvocations,
219+
busFailedInvocations
220+
]
221+
})
222+
);
223+
224+
// EventBridge Rule metrics
225+
const ruleWidgets = props?.router.rules?.map((rule) => {
226+
return new GraphWidget({
227+
title: `EventBridge Rule: ${rule.ruleName}`,
228+
width: 8,
229+
height: 6,
230+
left: [
231+
new Metric({
232+
namespace: 'AWS/Events',
233+
metricName: 'Invocations',
234+
dimensionsMap: { RuleName: rule.ruleName },
235+
period: cdk.Duration.minutes(5),
236+
statistic: 'Sum'
237+
}),
238+
new Metric({
239+
namespace: 'AWS/Events',
240+
metricName: 'FailedInvocations',
241+
dimensionsMap: { RuleName: rule.ruleName },
242+
period: cdk.Duration.minutes(5),
243+
statistic: 'Sum'
244+
}),
245+
new Metric({
246+
namespace: 'AWS/Events',
247+
metricName: 'ThrottledRules',
248+
dimensionsMap: { RuleName: rule.ruleName },
249+
period: cdk.Duration.minutes(5),
250+
statistic: 'Sum'
251+
})
252+
]
253+
});
254+
}) || [];
255+
256+
if (ruleWidgets.length > 0) {
257+
dashboard.addWidgets(...ruleWidgets);
258+
}
259+
260+
// SNS Topic metrics
261+
const topicWidgets = props?.router.topics?.map((topic, index) => {
262+
return new GraphWidget({
263+
title: `SNS Topic: ${topic.topicName}`,
264+
width: 8,
265+
height: 6,
266+
left: [
267+
topic.metricNumberOfNotificationsFailed(),
268+
topic.metricNumberOfNotificationsDelivered(),
269+
topic.metricNumberOfMessagesPublished()
270+
]
271+
});
272+
}) || [];
273+
274+
if (topicWidgets.length > 0) {
275+
dashboard.addWidgets(...topicWidgets);
276+
}
277+
278+
// SQS Queue metrics for consumers
279+
const queueWidgets = props?.consumers?.map((consumer) => {
280+
return new GraphWidget({
281+
title: `SQS Queue: ${consumer.queue.queueName}`,
282+
width: 12,
283+
height: 6,
284+
left: [
285+
consumer.queue.metricApproximateNumberOfMessagesVisible(),
286+
consumer.queue.metricApproximateAgeOfOldestMessage(),
287+
consumer.queue.metricNumberOfMessagesReceived(),
288+
consumer.queue.metricNumberOfMessagesDeleted()
289+
]
290+
});
291+
}) || [];
292+
293+
if (queueWidgets.length > 0) {
294+
dashboard.addWidgets(...queueWidgets);
295+
}
296+
297+
// Dead Letter Queue metrics
298+
const dlqWidgets = props?.deadLetterQueues?.map((queue) => {
299+
return new GraphWidget({
300+
title: `Dead Letter Queue: ${queue.queueName}`,
301+
width: 12,
302+
height: 6,
303+
left: [
304+
queue.metricApproximateNumberOfMessagesVisible(),
305+
queue.metricApproximateAgeOfOldestMessage()
306+
]
307+
});
308+
}) || [];
309+
310+
if (dlqWidgets.length > 0) {
311+
dashboard.addWidgets(...dlqWidgets);
312+
}
313+
314+
// Store the dashboard name for reference
315+
this.dashboardName = dashboard.dashboardName;
182316
}
183317
}

0 commit comments

Comments
 (0)