Skip to content

Commit

Permalink
feat: enable adding extra info to database cpu usage alarm
Browse files Browse the repository at this point in the history
  • Loading branch information
krissrex committed May 10, 2024
1 parent 1244e32 commit 565f57f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/alarms/__tests__/database-alarms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ test("create alarms", () => {
})
alarms.addCpuUtilizationAlarm({
threshold: 75,
appendToAlarmDescription: "Runbook at https://liflig.no",
})

alarms.addStorageSpaceAlarms({
Expand Down
8 changes: 5 additions & 3 deletions src/alarms/database-alarms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export class DatabaseAlarms extends constructs.Construct {
* @default 10% of the maximum earned CPU credits for the instance type.
*/
threshold?: number

/**
* Add extra information to the alarm description, like Runbook URL or steps to triage.
*/
Expand Down Expand Up @@ -186,7 +185,6 @@ export class DatabaseAlarms extends constructs.Construct {
*/
threshold?: cdk.Size
}

/**
* Add extra information to the alarm description, like Runbook URL or steps to triage.
*/
Expand Down Expand Up @@ -273,6 +271,10 @@ export class DatabaseAlarms extends constructs.Construct {
* @default 2 minutes
*/
period?: cdk.Duration
/**
* Add extra information to the alarm description, like Runbook URL or steps to triage.
*/
appendToAlarmDescription?: string
},
): void {
const alarm = new cloudwatch.Metric({
Expand All @@ -284,7 +286,7 @@ export class DatabaseAlarms extends constructs.Construct {
DBInstanceIdentifier: this.databaseInstanceIdentifier,
},
}).createAlarm(this, "CpuUtilizationAlarm", {
alarmDescription: `RDS database '${this.databaseInstanceIdentifier}' has a higher than expected CPU utilization.`,
alarmDescription: `RDS database '${this.databaseInstanceIdentifier}' has a higher than expected CPU utilization. ${props?.appendToAlarmDescription ?? ""}`,
comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
evaluationPeriods: props?.evaluationPeriods ?? 5,
threshold: props?.threshold ?? 80,
Expand Down

0 comments on commit 565f57f

Please sign in to comment.