-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathinteg.alarm-and-dashboard.ts
86 lines (78 loc) · 2.84 KB
/
integ.alarm-and-dashboard.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
// Integration test to deploy some resources, create an alarm on it and create a dashboard.
//
// Because literally every other library is going to depend on @aws-cdk/aws-cloudwatch, we drop down
// to the very lowest level to create CloudFormation resources by hand, without even generated
// library support.
import * as cdk from '@aws-cdk/core';
import * as cloudwatch from '../lib';
const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-cdk-cloudwatch-alarms');
const queue = new cdk.CfnResource(stack, 'queue', { type: 'AWS::SQS::Queue' });
const metric = new cloudwatch.Metric({
namespace: 'AWS/SQS',
metricName: 'ApproximateNumberOfMessagesVisible',
dimensions: { QueueName: queue.getAtt('QueueName') },
});
const alarm = metric.createAlarm(stack, 'Alarm', {
threshold: 100,
evaluationPeriods: 3,
datapointsToAlarm: 2,
});
const dashboard = new cloudwatch.Dashboard(stack, 'Dash', {
dashboardName: 'MyCustomDashboardName',
start: '-9H',
end: '2018-12-17T06:00:00.000Z',
periodOverride: cloudwatch.PeriodOverride.INHERIT,
});
dashboard.addWidgets(
new cloudwatch.TextWidget({ markdown: '# This is my dashboard' }),
new cloudwatch.TextWidget({ markdown: 'you like?' }),
);
dashboard.addWidgets(new cloudwatch.AlarmWidget({
title: 'Messages in queue',
alarm,
}));
dashboard.addWidgets(new cloudwatch.GraphWidget({
title: 'More messages in queue with alarm annotation',
left: [metric],
leftAnnotations: [alarm.toAnnotation()],
}));
dashboard.addWidgets(new cloudwatch.SingleValueWidget({
title: 'Current messages in queue',
metrics: [metric],
}));
dashboard.addWidgets(new cloudwatch.LogQueryWidget({
title: 'Errors in my log group',
logGroupNames: ['my-log-group'],
queryString: `fields @message
| filter @message like /Error/`,
}));
dashboard.addWidgets(new cloudwatch.LogQueryWidget({
title: 'Errors in my log group - bar',
view: cloudwatch.LogQueryVisualizationType.BAR,
logGroupNames: ['my-log-group'],
queryString: `fields @message
| filter @message like /Error/`,
}));
dashboard.addWidgets(new cloudwatch.LogQueryWidget({
title: 'Errors in my log group - line',
view: cloudwatch.LogQueryVisualizationType.LINE,
logGroupNames: ['my-log-group'],
queryString: `fields @message
| filter @message like /Error/`,
}));
dashboard.addWidgets(new cloudwatch.LogQueryWidget({
title: 'Errors in my log group - stacked',
view: cloudwatch.LogQueryVisualizationType.STACKEDAREA,
logGroupNames: ['my-log-group'],
queryString: `fields @message
| filter @message like /Error/`,
}));
dashboard.addWidgets(new cloudwatch.LogQueryWidget({
title: 'Errors in my log group - pie',
view: cloudwatch.LogQueryVisualizationType.PIE,
logGroupNames: ['my-log-group'],
queryString: `fields @message
| filter @message like /Error/`,
}));
app.synth();