in src/ecs.ts [65:156]
constructor(scope: Construct, id: string, props: WatchEcsServiceProps) {
super(scope, id);
this.watchful = props.watchful;
if (props.ec2Service) {
this.ecsService = props.ec2Service;
this.serviceName = props.ec2Service.serviceName;
this.clusterName = props.ec2Service.cluster.clusterName;
} else if (props.fargateService) {
this.ecsService = props.fargateService;
this.serviceName = props.fargateService.serviceName;
this.clusterName = props.fargateService.cluster.clusterName;
} else {
throw new Error('No service provided to monitor.');
}
this.targetGroup = props.targetGroup;
this.targetGroupName = this.targetGroup.targetGroupFullName;
this.loadBalancerName = this.targetGroup.firstLoadBalancerFullName;
this.metrics = new EcsMetricFactory();
this.watchful.addSection(props.title, {
links: [
{ title: 'ECS Service', url: linkForEcsService(this.ecsService) },
],
});
const { cpuUtilizationMetric, cpuUtilizationAlarm } = this.createCpuUtilizationMonitor(props.cpuMaximumThresholdPercent);
const { memoryUtilizationMetric, memoryUtilizationAlarm } = this.createMemoryUtilizationMonitor(props.memoryMaximumThresholdPercent);
const { targetResponseTimeMetric, targetResponseTimeAlarm } = this.createTargetResponseTimeMonitor(props.targetResponseTimeThreshold);
const { healthyHostsMetric, unhealthyHostsMetric } = this.createHostCountMetrics();
const { requestsMetric, requestsAlarm } = this.createRequestsMonitor(props.requestsThreshold);
const { http2xxMetric, http3xxMetric, http4xxMetric, http5xxMetric } = this.createHttpRequestsMetrics();
const { requestsErrorRateMetric, requestsErrorRateAlarm } = this.requestsErrorRate(props.requestsErrorRateThreshold);
this.watchful.addWidgets(
new cloudwatch.GraphWidget({
title: `CPUUtilization/${cpuUtilizationMetric.period.toMinutes()}min`,
width: 12,
left: [cpuUtilizationMetric],
leftAnnotations: [cpuUtilizationAlarm.toAnnotation()],
}),
new cloudwatch.GraphWidget({
title: `MemoryUtilization/${memoryUtilizationMetric.period.toMinutes()}min`,
width: 12,
left: [memoryUtilizationMetric],
leftAnnotations: [memoryUtilizationAlarm.toAnnotation()],
}),
);
this.watchful.addWidgets(
new cloudwatch.SingleValueWidget({
title: 'Healthy Hosts',
height: 6,
width: 6,
metrics: [healthyHostsMetric],
}),
new cloudwatch.SingleValueWidget({
title: 'UnHealthy Hosts',
height: 6,
width: 6,
metrics: [unhealthyHostsMetric],
}),
new cloudwatch.GraphWidget({
title: `TargetResponseTime/${targetResponseTimeMetric.period.toMinutes()}min`,
width: 6,
left: [targetResponseTimeMetric],
leftAnnotations: [targetResponseTimeAlarm.toAnnotation()],
}),
new cloudwatch.GraphWidget({
title: `Requests/${requestsMetric.period.toMinutes()}min`,
width: 6,
left: [requestsMetric],
leftAnnotations: [requestsAlarm.toAnnotation()],
}),
);
this.watchful.addWidgets(
new cloudwatch.GraphWidget({
title: 'HTTP Requests Overview',
width: 12,
left: [http2xxMetric, http3xxMetric, http4xxMetric, http5xxMetric],
}),
new cloudwatch.GraphWidget({
title: `HTTP Requests Error rate/${requestsErrorRateMetric.period.toMinutes()}min`,
width: 12,
left: [requestsErrorRateMetric],
leftAnnotations: [requestsErrorRateAlarm.toAnnotation()],
}),
);
}