This repository has been archived by the owner on Jan 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonitoring-facade.ts
126 lines (102 loc) · 3.68 KB
/
monitoring-facade.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { Duration } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { IWidget, PeriodOverride } from 'aws-cdk-lib/aws-cloudwatch';
import {
AlbFargateServiceMonitoring, AlbFargateServiceMonitoringProps,
} from './aws-fargate';
import { MetricFactory, MetricFactoryDefaults } from './metric-factory';
import {
HeaderLevel,
IDashboardSegment,
MonitoringDashboard,
SingleWidgetDashboardSegment,
HeaderWidget,
} from '../dashboard';
export interface MonitoringFacadeProps {
/**
* The name of the dashboard that is to be configured.
*/
readonly dashboardName: string;
/**
* The start of the time range to use for each widget on the dashboard.
*/
readonly dashboardDurationRange?: Duration;
/**
* Defines whether dashboard should follow the time ranges or inherit from metrics
*
* @default PeriodOverride.AUTO
*/
readonly dashboardPeriodOverride?: PeriodOverride;
readonly metricDefaults: MetricFactoryDefaults;
}
/**
* This is the main entry point for your monitoring stack.
* Create this construct and then create a chain of calls (`.monitorXXX`) to define your monitoring.
*
* The facade uses building blocks called segments.
* Each segment represents a related group of metrics to monitor.
* You can also add custom segments to the dashboard.
*/
export class MonitoringFacade extends Construct {
readonly segments : IDashboardSegment[];
readonly dashboard: MonitoringDashboard;
readonly currentScope: Construct;
readonly globalMetricFactoryDefaults: MetricFactoryDefaults;
constructor(scope: Construct, id: string, props: MonitoringFacadeProps) {
super(scope, id);
this.currentScope = scope;
this.segments = [];
this.globalMetricFactoryDefaults = props.metricDefaults;
this.dashboard = new MonitoringDashboard(this, 'DashboardFacade', {
dashboardName: props.dashboardName,
dashboardDurationRange: props.dashboardDurationRange,
periodOverride: props.dashboardPeriodOverride,
});
}
// returns a new instance of metric factory with the global metric defaults specified.
buildMetricFactory() {
return new MetricFactory({
globalDefaults: this.globalMetricFactoryDefaults,
});
}
// lets consumers add individual dashboard segment to the dashboard.
addSegment(segment: IDashboardSegment) {
this.segments.push(segment);
this.dashboard.addSegment(segment);
return this;
}
// lets consumers add large header section to their dashboard.
addLargeHeader(text: string) {
this.addWidget(new HeaderWidget(text, HeaderLevel.LARGE));
return this;
}
// lets consumers add medium header section to their dashboard.
addMediumHeader(text: string) {
this.addWidget(new HeaderWidget(text, HeaderLevel.MEDIUM));
return this;
}
// lets consumers add small header section to their dashboard.
addSmallHeader(text: string) {
this.addWidget(new HeaderWidget(text, HeaderLevel.SMALL));
return this;
}
// lets consumers add a custom widget to the dashboard.
addWidget(widget: IWidget) {
this.addSegment(new SingleWidgetDashboardSegment(widget));
return this;
}
// lets consumers add a list of custom widgets to the dashboard.
addWidgets(widgets: IWidget[]) {
widgets.forEach((widget) => {
this.addWidget(widget);
});
return this;
}
// lets consumers monitor the specified Alb fargate service in their dashboard.
monitorAlbFargateService(props: AlbFargateServiceMonitoringProps) {
const segment = new AlbFargateServiceMonitoring(this, props);
this.addSegment(segment);
// this.alarms.push(...segment.alarms);
return this;
}
}