-
Notifications
You must be signed in to change notification settings - Fork 0
/
mr_monitoring.ts
238 lines (222 loc) · 6.47 KB
/
mr_monitoring.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
* Copyright 2023-2024 Amazon.com, Inc. or its affiliates.
*/
import {
Dashboard,
GraphWidget,
GraphWidgetView,
LogQueryVisualizationType,
LogQueryWidget,
MathExpression,
SingleValueWidget
} from "aws-cdk-lib/aws-cloudwatch";
import { FargateService } from "aws-cdk-lib/aws-ecs";
import { Queue } from "aws-cdk-lib/aws-sqs";
import { Construct } from "constructs";
import { OSMLAccount } from "../../osml_account";
import { MRDataplaneConfig } from "../mr_dataplane";
/**
* Interface for MR Monitoring Props.
*
* @interface MRMonitoringProps
*/
export interface MRMonitoringProps {
/**
* The OSML account interface.
*
* @type {OSMLAccount}
*/
account: OSMLAccount;
/**
* The model runner region request queue.
*
* @type {Queue}
*/
regionRequestQueue: Queue;
/**
* The model runner region request DLQ (Dead Letter Queue).
*
* @type {Queue}
*/
regionRequestDlQueue: Queue;
/**
* The model runner image request queue.
*
* @type {Queue}
*/
imageRequestQueue: Queue;
/**
* The model runner image request DLQ (Dead Letter Queue).
*
* @type {Queue}
*/
imageRequestDlQueue: Queue;
/**
* The model runner Fargate service.
*
* @type {FargateService}
*/
service: FargateService;
/**
* The model runner dataplane configuration.
*
* @type {MRDataplaneConfig}
*/
mrDataplaneConfig: MRDataplaneConfig;
/**
* Optional model information.
*
* @type {string | undefined}
*/
model?: string;
}
/**
* Represents an MRMonitoring construct for monitoring various metrics and statistics.
*/
export class MRMonitoring extends Construct {
/**
* Creates a new MRMonitoring construct.
* @param {Construct} scope - The scope/stack in which to define this construct.
* @param {string} id - The id of this construct within the current scope.
* @param {MRMonitoringProps} props - The properties of this construct.
* @returns {MRMonitoring} - The MRMonitoring construct.
*/
public modelStatsWidget: SingleValueWidget;
public mrDashboard: Dashboard;
public requestsWidget: SingleValueWidget;
constructor(scope: Construct, id: string, props: MRMonitoringProps) {
super(scope, id);
// Create a dashboard for monitoring
this.mrDashboard = new Dashboard(this, "OSMLMRDashboard", {
dashboardName: "OSML-ModelRunner"
});
const topRowWidgets = [
new SingleValueWidget({
region: props.account.region,
title: "Counts",
width: 3,
height: 5,
metrics: [
new MathExpression({
label: "Images",
expression:
"SUM(SEARCH('{OSML/ModelRunner, InputFormat, ModelName, Operation} ImageProcessing Invocations', 'Sum'))"
}),
new MathExpression({
label: "Tiles",
expression:
"SUM(SEARCH('{OSML/ModelRunner, ModelName, Operation} TileProcessing Invocations', 'Sum'))"
})
],
sparkline: false
}),
new GraphWidget({
region: props.account.region,
title: "Average Image Processing Time (Seconds)",
view: GraphWidgetView.BAR,
height: 5,
width: 5,
left: [
new MathExpression({
label: "",
expression:
"SEARCH('{OSML/ModelRunner, InputFormat, ModelName, Operation} ImageProcessing Duration', 'Average')"
})
],
statistic: "Average",
leftAnnotations: [
{ color: "#2ca02c", label: "5m", value: 300 },
{ color: "#d62728", label: "15m", value: 900 }
]
}),
new GraphWidget({
region: props.account.region,
title: "Request Volume",
height: 5,
width: 11,
view: GraphWidgetView.TIME_SERIES,
stacked: false,
statistic: "Sum",
left: [
props.imageRequestQueue.metricNumberOfMessagesReceived({
label: "Image Requests Received",
statistic: "Sum"
}),
props.imageRequestQueue.metricApproximateNumberOfMessagesVisible({
label: "Image Requests Waiting",
statistic: "Sum"
})
]
}),
new GraphWidget({
region: props.account.region,
title: "Input Formats",
height: 5,
width: 5,
view: GraphWidgetView.PIE,
statistic: "Average",
left: [
new MathExpression({
expression:
"SEARCH('{OSML/ModelRunner, InputFormat, Operation} TileGeneration Invocations', 'Sum')",
label: ""
})
]
})
];
this.mrDashboard.addWidgets(...topRowWidgets);
this.mrDashboard.addWidgets(
new GraphWidget({
region: props.account.region,
title: "Model Utilization",
width: 24,
height: 6,
view: GraphWidgetView.TIME_SERIES,
stacked: false,
statistic: "Average",
left: [
new MathExpression({
expression:
"SEARCH('{OSML/ModelRunner, ModelName, Operation} ModelInvocation Duration', 'Average', 60)",
label: ""
})
],
right: [
new MathExpression({
expression:
"SEARCH('{OSML/ModelRunner, ModelName, Operation} ModelInvocation Invocations', 'Sum', 60)",
label: ""
}),
new MathExpression({
expression:
"SEARCH('{OSML/ModelRunner, ModelName, Operation} ModelInvocation Errors', 'Sum', 60)",
label: ""
}),
new MathExpression({
expression:
"SEARCH('{OSML/ModelRunner, ModelName, Operation} ModelInvocation Retries', 'Sum', 60)",
label: ""
})
]
})
);
this.mrDashboard.addWidgets(
new LogQueryWidget({
title: "Image Status",
width: 24,
height: 11,
region: props.account.region,
logGroupNames: ["/aws/OSML/MRService"],
view: LogQueryVisualizationType.TABLE,
queryLines: [
"fields job_id as Job, request.image_url as Image, request.model_name as Model, status as Status, ",
' concat(request.region_success, "/", request.region_count) as Regions, request.region_error as Failures,',
" fromMillis(request.start_time) as Start, fromMillis(request.end_time) as End",
'filter message = "StatusMonitorUpdate" and status in ["SUCCESS", "FAILED"]',
"sort @timestamp desc",
"limit 20"
]
})
);
}
}