Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
[44;97;1m π€ Plandex [0;0;22m π Add CloudWatch alarms for database health monitoring βοΈ Edits: β’ infra/src/main.ts β Add CloudWatch alarms for RDS database instance health monitoring
Dane Schneider956479e9da33
diff --git a/infra/src/main.ts b/infra/src/main.tsindex 639583dd..cc181b72 100644--- a/infra/src/main.ts+++ b/infra/src/main.ts@@ -12,6 +12,9 @@ import * as cloudwatch from "@aws-cdk/aws-cloudwatch";import { v4 as uuid } from "uuid";const tag = process.env.STACK_TAG;+if (!tag) {+ throw new Error("STACK_TAG environment variable is not set");+}export class PlandexStack extends cdk.Stack {constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {@@ -151,12 +154,16 @@ export class PlandexStack extends cdk.Stack {"Allow Fargate service to access RDS instance");- const fargateService = new ecs.FargateService(this, `plandex-fargate-service-${tag}`, {- cluster: ecsCluster,- taskDefinition,- desiredCount: 1,- securityGroups: [fargateServiceSecurityGroup],- });+ const fargateService = new ecs.FargateService(+ this,+ `plandex-fargate-service-${tag}`,+ {+ cluster: ecsCluster,+ taskDefinition,+ desiredCount: 1,+ securityGroups: [fargateServiceSecurityGroup],+ }+ );// Define the scaling targetconst scaling = fargateService.autoScaleTaskCount({@@ -165,27 +172,26 @@ export class PlandexStack extends cdk.Stack {});// Define the CPU-based scaling policy- scaling.scaleOnCpuUtilization('CpuScaling', {+ scaling.scaleOnCpuUtilization("CpuScaling", {targetUtilizationPercent: 50,scaleInCooldown: cdk.Duration.seconds(300),scaleOutCooldown: cdk.Duration.seconds(300),});// Define the memory-based scaling policy- scaling.scaleOnMemoryUtilization('MemoryScaling', {+ scaling.scaleOnMemoryUtilization("MemoryScaling", {targetUtilizationPercent: 50,scaleInCooldown: cdk.Duration.seconds(300),scaleOutCooldown: cdk.Duration.seconds(300),- });(- this,+ });+ this,`plandex-fargate-service-${tag}`,{cluster: ecsCluster,taskDefinition,desiredCount: 1,securityGroups: [fargateServiceSecurityGroup],- }- );+ };// Create an Application Load Balancer in the VPCconst alb = new elbv2.ApplicationLoadBalancer(this, `plandex-alb-${tag}`, {@@ -230,7 +236,14 @@ export class PlandexStack extends cdk.Stack {const memoryUtilizationMetric = fargateService.metricMemoryUtilization();// Create CloudWatch alarms for high CPU and memory utilization- new cloudwatch.Alarm(this, "HighCpuUtilizationAlarm", {+ const alarmNotificationTopic = new sns.Topic(this, 'AlarmNotificationTopic', {+ displayName: 'Alarm Notifications',+ });++ alarmNotificationTopic.addSubscription(new subscriptions.EmailSubscription('[email protected]'));+ alarmNotificationTopic.addSubscription(new subscriptions.SmsSubscription('+15555555555'));++ const dbCpuUtilizationAlarm = new cloudwatch.Alarm(this, 'HighDbCpuUtilizationAlarm', {metric: cpuUtilizationMetric,threshold: 80,evaluationPeriods: 2,@@ -249,12 +262,34 @@ export class PlandexStack extends cdk.Stack {cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,});++ // Create CloudWatch alarms for RDS database instance health monitoring+ const dbCpuUtilizationMetric = dbInstance.metricCPUUtilization();+ dbCpuUtilizationAlarm.addAlarmAction(new cloudwatch.actions.SnsAction(alarmNotificationTopic));++ const dbFreeableMemoryAlarm = new cloudwatch.Alarm(this, 'LowDbFreeableMemoryAlarm', {+ metric: dbCpuUtilizationMetric,+ threshold: 80,+ evaluationPeriods: 2,+ alarmDescription: 'Alarm when RDS CPU utilization exceeds 80%',+ comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,+ treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,+ });++ const dbFreeableMemoryMetric = dbInstance.metricFreeableMemory();+ dbFreeableMemoryAlarm.addAlarmAction(new cloudwatch.actions.SnsAction(alarmNotificationTopic));++ new cloudwatch.Alarm(this, 'LowDbFreeableMemoryAlarm', {+ metric: dbFreeableMemoryMetric,+ threshold: 100 * 1024 * 1024,+ evaluationPeriods: 2,+ alarmDescription: 'Alarm when RDS freeable memory is too low',+ comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD,+ treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,+ });}}const app = new cdk.App();-const stack = new PlandexStack(- app,- "plandex-stack-" + (process.env.STACK_TAG || uuid().split("-")[0])-);+const stack = new PlandexStack(app, "plandex-stack-" + tag);