in src/api-gateway.ts [55:93]
constructor(scope: Construct, id: string, props: WatchApiGatewayProps) {
super(scope, id);
this.api = props.restApi.node.findChild('Resource') as apigw.CfnRestApi;
this.apiName = this.api.name!;
this.stage = props.restApi.deploymentStage.stageName;
this.watchful = props.watchful;
this.metrics = new ApiGatewayMetricFactory();
const alarmThreshold = props.serverErrorThreshold == null ? 1 : props.serverErrorThreshold;
if (alarmThreshold) {
const count5xxMetric = this.metrics.metricErrors(this.apiName, this.stage).count5XX.with({
statistic: 'sum',
period: Duration.minutes(5),
});
this.watchful.addAlarm(
count5xxMetric.createAlarm(this, '5XXErrorAlarm', {
alarmDescription: `at ${alarmThreshold}`,
threshold: alarmThreshold,
comparisonOperator:
ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
evaluationPeriods: 1,
}),
);
}
this.watchful.addSection(props.title, {
links: [{ title: 'Amazon API Gateway Console', url: linkForApiGateway(props.restApi) }],
});
[undefined, ...props.watchedOperations || []].forEach(operation =>
this.watchful.addWidgets(
this.createCallGraphWidget(operation, alarmThreshold),
...props.cacheGraph ? [this.createCacheGraphWidget(operation)] : [],
this.createLatencyGraphWidget(operation),
this.createIntegrationLatencyGraphWidget(operation),
),
);
}