Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: minor cleanup #545

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ The order of precedence of the region/account values is:
1. The facade's `metricFactoryDefaults` props.
1. The region/account that the stack is deployed to.

Note that certain metrics are based on [math expressions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html) and cannot be alarmed upon in a cross-account cross-Region context, and you will see an error at synthesis time.
Note that while this allows for cross-account cross-Region dashboarding, cross-Region alarming is not supported by CloudWatch.

### Monitoring scopes

Expand Down
6 changes: 2 additions & 4 deletions lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
}

metric4XXErrorRate() {
const metric = this.metric4XXErrorCount();
return this.metricFactory.toRate(
metric,
this.metric4XXErrorCount(),
this.rateComputationMethod,
false,
"errors",
Expand All @@ -139,9 +138,8 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
}

metric5XXFaultRate() {
const metric = this.metric5XXFaultCount();
return this.metricFactory.toRate(
metric,
this.metric5XXFaultCount(),
this.rateComputationMethod,
false,
"faults",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
}

metric4xxRate() {
const metric = this.metric4xxCount();
return this.metricFactory.toRate(
metric,
this.metric4xxCount(),
this.rateComputationMethod,
false,
"errors",
Expand All @@ -132,9 +131,8 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
}

metric5xxRate() {
const metric = this.metric5xxCount();
return this.metricFactory.toRate(
metric,
this.metric5xxCount(),
this.rateComputationMethod,
false,
"faults",
Expand Down
6 changes: 2 additions & 4 deletions lib/monitoring/aws-appsync/AppSyncMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
}

metric4XXErrorRate() {
const metric = this.metric4XXErrorCount();
return this.metricFactory.toRate(
metric,
this.metric4XXErrorCount(),
this.rateComputationMethod,
false,
"errors",
Expand All @@ -162,9 +161,8 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
}

metric5XXFaultRate() {
const metric = this.metric5XXFaultCount();
return this.metricFactory.toRate(
metric,
this.metric5XXFaultCount(),
this.rateComputationMethod,
false,
"faults",
Expand Down
1 change: 0 additions & 1 deletion lib/monitoring/aws-billing/BillingMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class BillingMetricFactory {

metricTotalCostInUsd(): MetricWithAlarmSupport {
// not using metric factory because we customize everything

return new Metric({
namespace: BillingNamespace,
metricName: BillingMetric,
Expand Down
6 changes: 2 additions & 4 deletions lib/monitoring/aws-docdb/DocumentDbMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,18 @@ export class DocumentDbMetricFactory extends BaseMetricFactory<DocumentDbMetricF
}

metricReadLatencyInMillis(latencyType: LatencyType) {
const label = "Read " + getLatencyTypeLabel(latencyType);
return this.metric(
"ReadLatency",
getLatencyTypeStatistic(latencyType),
label,
`Read ${getLatencyTypeLabel(latencyType)}`,
);
}

metricWriteLatencyInMillis(latencyType: LatencyType) {
const label = "Write " + getLatencyTypeLabel(latencyType);
return this.metric(
"WriteLatency",
getLatencyTypeStatistic(latencyType),
label,
`Write ${getLatencyTypeLabel(latencyType)}`,
);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/monitoring/aws-ecs-patterns/BaseServiceMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ export class BaseServiceMetricFactory extends BaseMetricFactory<BaseServiceMetri
}

metricEphemeralStorageUsageInPercent() {
const total = this.metricEphemeralStorageReserved();
const used = this.metricEphemeralStorageUtilized();

return this.metricFactory.createMetricMath(
"100 * (used/total)",
{ used, total },
{
used: this.metricEphemeralStorageUtilized(),
total: this.metricEphemeralStorageReserved(),
},
"Ephemeral Storage Usage",
);
}
Expand Down
6 changes: 2 additions & 4 deletions lib/monitoring/aws-lambda/LambdaFunctionMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ export class LambdaFunctionMetricFactory extends BaseMetricFactory<LambdaFunctio
}

metricThrottlesRate() {
const metric = this.metricThrottlesCount();
return this.metricFactory.toRate(
metric,
this.metricThrottlesCount(),
this.rateComputationMethod,
false,
"throttles",
Expand All @@ -112,9 +111,8 @@ export class LambdaFunctionMetricFactory extends BaseMetricFactory<LambdaFunctio
}

metricFaultRate() {
const metric = this.metricFaultCount();
return this.metricFactory.toRate(
metric,
this.metricFaultCount(),
this.rateComputationMethod,
false,
"faults",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ export class ApplicationLoadBalancerMetricFactory
}

metricHealthyTaskInPercent() {
const healthyTaskCount = this.metricHealthyTaskCount();
const unhealthyTaskCount = this.metricUnhealthyTaskCount();
return this.metricFactory.createMetricMath(
"(healthyTaskCount / (healthyTaskCount + unhealthyTaskCount)) * 100",
{ healthyTaskCount, unhealthyTaskCount },
{
healthyTaskCount: this.metricHealthyTaskCount(),
unhealthyTaskCount: this.metricUnhealthyTaskCount(),
},
"Healthy Task Percent (avg: ${AVG})",
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ export class NetworkLoadBalancerMetricFactory
}

metricHealthyTaskInPercent() {
const healthyTaskCount = this.metricHealthyTaskCount();
const unhealthyTaskCount = this.metricUnhealthyTaskCount();
return this.metricFactory.createMetricMath(
"(healthyTaskCount / (healthyTaskCount + unhealthyTaskCount)) * 100",
{ healthyTaskCount, unhealthyTaskCount },
{
healthyTaskCount: this.metricHealthyTaskCount(),
unhealthyTaskCount: this.metricUnhealthyTaskCount(),
},
"Healthy Task Percent (avg: ${AVG})",
);
}
Expand Down
8 changes: 5 additions & 3 deletions lib/monitoring/aws-rds/RdsClusterMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ export class RdsClusterMetricFactory extends BaseMetricFactory<RdsClusterMetricF
}

metricDiskSpaceUsageInPercent() {
const used = this.metricUsedStorageInBytes();
const free = this.metricFreeStorageInBytes();
return this.metricFactory.createMetricMath(
"100 * (used/(used+free))",
{ used, free },
{
used: this.metricUsedStorageInBytes(),
free: this.metricFreeStorageInBytes(),
},
"Disk Usage",
);
}
Expand Down Expand Up @@ -118,6 +119,7 @@ export class RdsClusterMetricFactory extends BaseMetricFactory<RdsClusterMetricF
"Cluster is not of type `ServerlessCluster`. Metric is not applicable",
);
}

return this.metric(
"ServerlessDatabaseCapacity",
MetricStatistic.AVERAGE,
Expand Down
6 changes: 2 additions & 4 deletions lib/monitoring/aws-rds/RdsInstanceMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ export class RdsInstanceMetricFactory extends BaseMetricFactory<RdsInstanceMetri
}

metricReadLatencyInMillis(latencyType: LatencyType) {
const label = "ReadLatency " + getLatencyTypeLabel(latencyType);
return this.metric(
"ReadLatency",
getLatencyTypeStatistic(latencyType),
label,
`ReadLatency ${getLatencyTypeLabel(latencyType)}`,
);
}

Expand All @@ -111,11 +110,10 @@ export class RdsInstanceMetricFactory extends BaseMetricFactory<RdsInstanceMetri
}

metricWriteLatencyInMillis(latencyType: LatencyType) {
const label = "WriteLatency " + getLatencyTypeLabel(latencyType);
return this.metric(
"WriteLatency",
getLatencyTypeStatistic(latencyType),
label,
`WriteLatency ${getLatencyTypeLabel(latencyType)}`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ export class StepFunctionLambdaIntegrationMetricFactory extends BaseMetricFactor
}

metricFunctionsFailedRate() {
const metric = this.metricFunctionsFailed();
return this.metricFactory.toRate(
metric,
this.metricFunctionsFailed(),
this.rateComputationMethod,
false,
"faults",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ export class StepFunctionMetricFactory extends BaseMetricFactory<StepFunctionMet
}

metricExecutionsFailedRate() {
const metric = this.metricExecutionsFailed();
return this.metricFactory.toRate(
metric,
this.metricExecutionsFailed(),
this.rateComputationMethod,
false,
"faults",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ export class StepFunctionServiceIntegrationMetricFactory extends BaseMetricFacto
}

metricServiceIntegrationsFailedRate() {
const metric = this.metricServiceIntegrationsFailed();
return this.metricFactory.toRate(
metric,
this.metricServiceIntegrationsFailed(),
this.rateComputationMethod,
false,
"faults",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ export class SyntheticsCanaryMetricFactory extends BaseMetricFactory<SyntheticsC
}

metric4xxErrorRate() {
const metric = this.metric4xxErrorCount();
return this.metricFactory.toRate(
metric,
this.metric4xxErrorCount(),
this.rateComputationMethod,
false,
"errors",
Expand All @@ -103,9 +102,8 @@ export class SyntheticsCanaryMetricFactory extends BaseMetricFactory<SyntheticsC
}

metric5xxFaultRate() {
const metric = this.metric5xxFaultCount();
return this.metricFactory.toRate(
metric,
this.metric5xxFaultCount(),
this.rateComputationMethod,
false,
"faults",
Expand Down