Skip to content

Commit

Permalink
feat(cloudwatch): add addMinIncomingLogsAlarm (#310)
Browse files Browse the repository at this point in the history
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_
  • Loading branch information
echeung-amzn authored Jan 27, 2023
1 parent 7dfbbc7 commit 6414368
Show file tree
Hide file tree
Showing 7 changed files with 645 additions and 65 deletions.
189 changes: 173 additions & 16 deletions API.md

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ You can browse the documentation at https://constructs.dev/packages/cdk-monitori
| 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 |
| AWS Certificate Manager (`.monitorCertificate()`) | Certificate expiration | Days until expiration | |
| AWS CloudFront (`.monitorCloudFrontDistribution()`) | TPS, traffic, latency, errors | Error rate, low/high TPS | |
| AWS CloudWatch Logs (`.monitorLog()`) | Patterns present in the log group | | |
| AWS CloudWatch Logs (`.monitorLog()`) | Patterns present in the log group | Minimum incoming logs | |
| AWS CloudWatch Synthetics Canary (`.monitorSyntheticsCanary()`) | Latency, error count/rate | Error count/rate, latency | |
| AWS CodeBuild (`.monitorCodeBuildProject()`) | Build counts (total, successful, failed), failed rate, duration | Failed build count/rate, duration | |
| AWS DocumentDB (`.monitorDocumentDbCluster()`) | CPU, throttling, read/write latency, transactions, cursors | CPU | |
Expand Down
38 changes: 38 additions & 0 deletions lib/monitoring/aws-cloudwatch/CloudWatchLogsMetricFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch";

import { MetricFactory, MetricStatistic } from "../../common";

const CloudWatchLogsNamespace = "AWS/Logs";

export interface CloudWatchLogsMetricFactoryProps {
/**
* Name of the log group to monitor.
*/
readonly logGroupName: string;
}

export class CloudWatchLogsMetricFactory {
private readonly metricFactory: MetricFactory;
private readonly dimensionsMap: DimensionsMap;

constructor(
metricFactory: MetricFactory,
props: CloudWatchLogsMetricFactoryProps
) {
this.metricFactory = metricFactory;
this.dimensionsMap = {
LogGroupName: props.logGroupName,
};
}

metricIncomingLogEvents() {
return this.metricFactory.createMetric(
"IncomingLogEvents",
MetricStatistic.N,
"Logs",
this.dimensionsMap,
undefined,
CloudWatchLogsNamespace
);
}
}
Loading

0 comments on commit 6414368

Please sign in to comment.