-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcdk-lambda-dashboard-stack.ts
134 lines (114 loc) · 3.96 KB
/
cdk-lambda-dashboard-stack.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
import * as cdk from '@aws-cdk/core';
import { Dashboard, GraphWidget, Metric } from '@aws-cdk/aws-cloudwatch';
export interface LambdaDashboardsStackProps extends cdk.StackProps {
dashboardName: string;
}
export class CdkLambdaDashboardStack extends cdk.Stack {
protected readonly lambdaDashboard: Dashboard;
protected readonly invocations = new Metric({
namespace: "AWS/Lambda",
metricName: "Invocations",
statistic: "sum"
});
protected readonly duration = new Metric({
namespace: "AWS/Lambda",
metricName: "Duration",
statistic: "min"
});
protected readonly errors = new Metric({
namespace: "AWS/Lambda",
metricName: "Errors",
statistic: "sum"
});
protected readonly throttles = new Metric({
namespace: "AWS/Lambda",
metricName: "Throttles",
statistic: "sum"
});
protected readonly provisionedConcurrencySpillovers = new Metric({
namespace: "AWS/Lambda",
metricName: "ProvisionedConcurrencySpilloverInvocations",
statistic: "sum"
});
protected readonly concurrentExecutions = new Metric({
namespace: "AWS/Lambda",
metricName: "ConcurrentExecutions",
statistic: "sum"
});
protected readonly provisionedConcurrentExecutions = new Metric({
namespace: "AWS/Lambda",
metricName: "ProvisionedConcurrentExecutions",
statistic: "sum"
});
protected readonly provisionedConcurrencyUtilization = new Metric({
namespace: "AWS/Lambda",
metricName: "ProvisionedConcurrencyUtilization",
statistic: "sum"
});
constructor(scope: cdk.App, id: string, props: LambdaDashboardsStackProps) {
super(scope, id, props);
this.lambdaDashboard = new Dashboard(this, props.dashboardName, {
dashboardName: props.dashboardName
});
}
// adds one row to dashboard for each lambda function
public addLambda(functionName: string, displayName: string) {
const dimensions = {
"FunctionName": functionName
};
this.lambdaDashboard.addWidgets(
new GraphWidget({
title: displayName + " Invocations",
left: [
this.invocations.with({
dimensions: dimensions,
}),
]
}),
new GraphWidget({
title: displayName + " Duration",
left: [
this.duration.with({
dimensions: dimensions,
}),
this.duration.with({
dimensions: dimensions,
statistic: "avg"
}),
this.duration.with({
dimensions: dimensions,
statistic: "max"
}),
]
}),
new GraphWidget({
title: displayName + " Errors",
left: [
this.errors.with({
dimensions: dimensions,
}),
this.throttles.with({
dimensions: dimensions,
}),
this.provisionedConcurrencySpillovers.with({
dimensions: dimensions,
})
]
}),
new GraphWidget({
title: displayName + " ConcurrentExecutions",
right: [
this.concurrentExecutions.with({
dimensions: dimensions,
}),
this.provisionedConcurrentExecutions.with({
dimensions: dimensions,
}),
this.provisionedConcurrencyUtilization.with({
dimensions: dimensions,
})
]
}),
);
}
}