Skip to content

Commit

Permalink
Merge pull request #196 from capralifecycle/fix-units-in-alarms
Browse files Browse the repository at this point in the history
Fix units in alarms
  • Loading branch information
stekern authored Jun 21, 2023
2 parents 4e3e216 + 2aa9136 commit 9ecde22
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.

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

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

12 changes: 4 additions & 8 deletions src/alarms/database-alarms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as constructs from "constructs"
import * as cdk from "aws-cdk-lib"
import * as cloudwatch from "aws-cdk-lib/aws-cloudwatch"
import * as ec2 from "aws-cdk-lib/aws-ec2"
import { Unit } from "aws-cdk-lib/aws-cloudwatch"

export interface DatabaseAlarmsProps {
/**
Expand Down Expand Up @@ -118,7 +117,6 @@ export class DatabaseAlarms extends constructs.Construct {
metricName: "CPUCreditBalance",
namespace: "AWS/RDS",
statistic: "Minimum",
unit: Unit.COUNT,
period: cdk.Duration.minutes(5),
dimensionsMap: {
DBInstanceIdentifier: this.databaseInstanceIdentifier,
Expand Down Expand Up @@ -192,7 +190,6 @@ export class DatabaseAlarms extends constructs.Construct {
metricName: "FreeStorageSpace",
namespace: "AWS/RDS",
statistic: "Minimum",
unit: Unit.GIGABYTES,
period: cdk.Duration.minutes(5),
dimensionsMap: {
DBInstanceIdentifier: this.databaseInstanceIdentifier,
Expand All @@ -202,8 +199,8 @@ export class DatabaseAlarms extends constructs.Construct {
comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD,
evaluationPeriods: 1,
threshold:
props?.lowStorageSpaceAlarm?.threshold?.toGibibytes() ??
this.allocatedStorage.toGibibytes() * 0.25,
props?.lowStorageSpaceAlarm?.threshold?.toBytes() ??
this.allocatedStorage.toBytes() * 0.25,
treatMissingData: cloudwatch.TreatMissingData.IGNORE,
})
if (props?.lowStorageSpaceAlarm?.enabled ?? true) {
Expand All @@ -219,7 +216,6 @@ export class DatabaseAlarms extends constructs.Construct {
metricName: "FreeStorageSpace",
namespace: "AWS/RDS",
statistic: "Minimum",
unit: Unit.GIGABYTES,
period: cdk.Duration.minutes(5),
dimensionsMap: {
DBInstanceIdentifier: this.databaseInstanceIdentifier,
Expand All @@ -229,8 +225,8 @@ export class DatabaseAlarms extends constructs.Construct {
comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD,
evaluationPeriods: 1,
threshold:
props?.criticallyLowStorageSpaceAlarm?.threshold?.toGibibytes() ??
this.allocatedStorage.toGibibytes() * 0.05,
props?.criticallyLowStorageSpaceAlarm?.threshold?.toBytes() ??
this.allocatedStorage.toBytes() * 0.05,
treatMissingData: cloudwatch.TreatMissingData.IGNORE,
})
if (props?.criticallyLowStorageSpaceAlarm?.enabled ?? true) {
Expand Down
3 changes: 1 addition & 2 deletions src/alarms/service-alarms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ export class ServiceAlarms extends constructs.Construct {
namespace: "AWS/ApplicationELB",
statistic: "p95",
period: props.targetResponseTimeAlarm?.period ?? cdk.Duration.minutes(5),
unit: cloudwatch.Unit.MILLISECONDS,
dimensionsMap: {
LoadBalancer: props.loadBalancerFullName,
TargetGroup: props.targetGroupFullName,
Expand All @@ -308,7 +307,7 @@ export class ServiceAlarms extends constructs.Construct {
evaluationPeriods: props.targetResponseTimeAlarm?.evaluationPeriods ?? 1,
threshold: (
props.targetResponseTimeAlarm?.threshold ?? cdk.Duration.millis(500)
).toMilliseconds(),
).toSeconds({ integral: false }),
treatMissingData: cloudwatch.TreatMissingData.IGNORE,
})
if (props.targetResponseTimeAlarm?.enabled ?? true) {
Expand Down

0 comments on commit 9ecde22

Please sign in to comment.