Skip to content

Commit 6414368

Browse files
author
Eugene Cheung
authored
feat(cloudwatch): add addMinIncomingLogsAlarm (#310)
Add ability to alarm on minimum number from `IncomingLogEvents` metric for a given CloudWatch log group. This is useful for detecting issues that would surface as missing incoming logs as a symptom (e.g., improper permissions, service outage/configuration issue, etc.). All available metrics: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatch-Logs-Monitoring-CloudWatch-Metrics.html --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent 7dfbbc7 commit 6414368

File tree

7 files changed

+645
-65
lines changed

7 files changed

+645
-65
lines changed

API.md

Lines changed: 173 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ You can browse the documentation at https://constructs.dev/packages/cdk-monitori
7474
| AWS Billing (`.monitorBilling()`) | AWS account cost | Total cost (anomaly) | [Requires enabling](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/gs_monitor_estimated_charges_with_cloudwatch.html#gs_turning_on_billing_metrics) the **Receive Billing Alerts** option in AWS Console / Billing Preferences |
7575
| AWS Certificate Manager (`.monitorCertificate()`) | Certificate expiration | Days until expiration | |
7676
| AWS CloudFront (`.monitorCloudFrontDistribution()`) | TPS, traffic, latency, errors | Error rate, low/high TPS | |
77-
| AWS CloudWatch Logs (`.monitorLog()`) | Patterns present in the log group | | |
77+
| AWS CloudWatch Logs (`.monitorLog()`) | Patterns present in the log group | Minimum incoming logs | |
7878
| AWS CloudWatch Synthetics Canary (`.monitorSyntheticsCanary()`) | Latency, error count/rate | Error count/rate, latency | |
7979
| AWS CodeBuild (`.monitorCodeBuildProject()`) | Build counts (total, successful, failed), failed rate, duration | Failed build count/rate, duration | |
8080
| AWS DocumentDB (`.monitorDocumentDbCluster()`) | CPU, throttling, read/write latency, transactions, cursors | CPU | |
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch";
2+
3+
import { MetricFactory, MetricStatistic } from "../../common";
4+
5+
const CloudWatchLogsNamespace = "AWS/Logs";
6+
7+
export interface CloudWatchLogsMetricFactoryProps {
8+
/**
9+
* Name of the log group to monitor.
10+
*/
11+
readonly logGroupName: string;
12+
}
13+
14+
export class CloudWatchLogsMetricFactory {
15+
private readonly metricFactory: MetricFactory;
16+
private readonly dimensionsMap: DimensionsMap;
17+
18+
constructor(
19+
metricFactory: MetricFactory,
20+
props: CloudWatchLogsMetricFactoryProps
21+
) {
22+
this.metricFactory = metricFactory;
23+
this.dimensionsMap = {
24+
LogGroupName: props.logGroupName,
25+
};
26+
}
27+
28+
metricIncomingLogEvents() {
29+
return this.metricFactory.createMetric(
30+
"IncomingLogEvents",
31+
MetricStatistic.N,
32+
"Logs",
33+
this.dimensionsMap,
34+
undefined,
35+
CloudWatchLogsNamespace
36+
);
37+
}
38+
}

0 commit comments

Comments
 (0)