-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rds): add support for RDS Instance Monitoring (#496)
Fixes #236 Added support for monitoring RDS Instances. Implementation is largely based on RDS Cluster monitoring code and includes the metrics necessary to recreate the "automatic" Cloud Watch dashboard. This implementation supports my needs, but further metrics can be added if there is a interest. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
- Loading branch information
Showing
11 changed files
with
3,016 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; | ||
import { IDatabaseInstance } from "aws-cdk-lib/aws-rds"; | ||
|
||
import { | ||
LatencyType, | ||
MetricFactory, | ||
MetricStatistic, | ||
getLatencyTypeLabel, | ||
getLatencyTypeStatistic, | ||
} from "../../common"; | ||
|
||
const RdsNamespace = "AWS/RDS"; | ||
|
||
export interface RdsInstanceMetricFactoryProps { | ||
/** | ||
* database instance | ||
*/ | ||
readonly instance: IDatabaseInstance; | ||
} | ||
|
||
export class RdsInstanceMetricFactory { | ||
readonly instanceIdentifier: string; | ||
readonly instance: IDatabaseInstance; | ||
protected readonly metricFactory: MetricFactory; | ||
protected readonly dimensionsMap: DimensionsMap; | ||
|
||
constructor( | ||
metricFactory: MetricFactory, | ||
props: RdsInstanceMetricFactoryProps | ||
) { | ||
this.metricFactory = metricFactory; | ||
this.instance = props.instance; | ||
this.instanceIdentifier = props.instance.instanceIdentifier; | ||
this.dimensionsMap = { | ||
DBInstanceIdentifier: this.instanceIdentifier, | ||
}; | ||
} | ||
|
||
metricTotalConnectionCount() { | ||
return this.metricFactory.adaptMetric( | ||
this.instance.metricDatabaseConnections({ | ||
statistic: MetricStatistic.SUM, | ||
label: "Connections: Sum", | ||
}) | ||
); | ||
} | ||
|
||
metricAverageCpuUsageInPercent() { | ||
return this.metricFactory.adaptMetric( | ||
this.instance.metricCPUUtilization({ | ||
statistic: MetricStatistic.AVERAGE, | ||
label: "CPU Usage", | ||
}) | ||
); | ||
} | ||
|
||
metricMaxFreeStorageSpace() { | ||
return this.metricFactory.adaptMetric( | ||
this.instance.metricFreeStorageSpace({ | ||
statistic: MetricStatistic.MAX, | ||
label: "FreeStorageSpace: MAX", | ||
}) | ||
); | ||
} | ||
|
||
metricAverageFreeableMemory() { | ||
return this.metricFactory.adaptMetric( | ||
this.instance.metricFreeableMemory({ | ||
statistic: MetricStatistic.AVERAGE, | ||
label: "FreeStorageSpace: Average", | ||
}) | ||
); | ||
} | ||
|
||
metricReadLatencyInMillis(latencyType: LatencyType) { | ||
const label = "ReadLatency " + getLatencyTypeLabel(latencyType); | ||
return this.metric( | ||
"ReadLatency", | ||
getLatencyTypeStatistic(latencyType), | ||
label | ||
); | ||
} | ||
|
||
metricReadThroughput() { | ||
return this.metric( | ||
"ReadThroughput", | ||
MetricStatistic.AVERAGE, | ||
"ReadThroughput: Average" | ||
); | ||
} | ||
|
||
metricReadIops() { | ||
return this.metricFactory.adaptMetric( | ||
this.instance.metricReadIOPS({ | ||
statistic: MetricStatistic.AVERAGE, | ||
label: "ReadIOPS: Average", | ||
}) | ||
); | ||
} | ||
|
||
metricWriteLatencyInMillis(latencyType: LatencyType) { | ||
const label = "WriteLatency " + getLatencyTypeLabel(latencyType); | ||
return this.metric( | ||
"WriteLatency", | ||
getLatencyTypeStatistic(latencyType), | ||
label | ||
); | ||
} | ||
|
||
metricWriteThroughput() { | ||
return this.metric( | ||
"WriteThroughput", | ||
MetricStatistic.AVERAGE, | ||
"WriteThroughput: Average" | ||
); | ||
} | ||
|
||
metricWriteIops() { | ||
return this.metricFactory.adaptMetric( | ||
this.instance.metricWriteIOPS({ | ||
statistic: MetricStatistic.AVERAGE, | ||
label: "WriteIOPS: Average", | ||
}) | ||
); | ||
} | ||
|
||
private metric( | ||
metricName: string, | ||
statistic: MetricStatistic, | ||
label: string | ||
) { | ||
return this.metricFactory.createMetric( | ||
metricName, | ||
statistic, | ||
label, | ||
this.dimensionsMap, | ||
undefined, | ||
RdsNamespace | ||
); | ||
} | ||
} |
Oops, something went wrong.