UNPKG

@renovosolutions/cdk-library-cloudwatch-alarms

Version:

AWS CDK Construct Library to automatically create CloudWatch Alarms for resources in a CDK app based on resource type.

575 lines (574 loc) 23.3 kB
import { IAspect, aws_sns as sns, aws_cloudwatch as cloudwatch, Duration } from 'aws-cdk-lib'; import { IConstruct, Construct } from 'constructs'; import { AlarmBaseProps } from './common'; /** * The recommended metrics for SNS topic alarms. */ export declare enum SnsRecommendedAlarmsMetrics { /** * The number of messages published to the topic. */ NUMBER_OF_MESSAGES_PUBLISHED = "NumberOfMessagesPublished", /** * The number of notifications delivered. */ NUMBER_OF_NOTIFICATIONS_DELIVERED = "NumberOfNotificationsDelivered", /** * The number of notifications failed. */ NUMBER_OF_NOTIFICATIONS_FAILED = "NumberOfNotificationsFailed", /** * The number of notifications filtered out due to invalid attributes. */ NUMBER_OF_NOTIFICATIONS_FILTERED_OUT_INVALID_ATTRIBUTES = "NumberOfNotificationsFilteredOut-InvalidAttributes", /** * The number of notifications filtered out due to invalid message body. */ NUMBER_OF_NOTIFICATIONS_FILTERED_OUT_INVALID_MESSAGE_BODY = "NumberOfNotificationsFilteredOut-InvalidMessageBody", /** * The number of notifications redriven to the dead-letter queue. */ NUMBER_OF_NOTIFICATIONS_REDRIVEN_TO_DLQ = "NumberOfNotificationsRedrivenToDlq", /** * The number of notifications failed to redrive to the dead-letter queue. */ NUMBER_OF_NOTIFICATIONS_FAILED_TO_REDRIVE_TO_DLQ = "NumberOfNotificationsFailedToRedriveToDlq" } export interface SnsAlarmBaseConfig extends AlarmBaseProps { /** * The period over which the specified statistic is applied. * * @default Duration.minutes(1) */ readonly period?: Duration; /** * The number of periods over which data is compared to the specified threshold. * * @default 5 */ readonly evaluationPeriods?: number; /** * The number of data points that must be breaching to trigger the alarm. * * @default 5 */ readonly datapointsToAlarm?: number; } /** * Configuration for the NumberOfMessagesPublished alarm. */ export interface SnsNumberOfMessagesPublishedAlarmConfig extends SnsAlarmBaseConfig { /** * The value against which the specified statistic is compared. * * The number of messages published should be in line with the expected number of * published messages for your application. You can also analyze the historical data, * trends and traffic to find the right threshold. */ readonly threshold: number; /** * The alarm name. * * @default - topic.topicName + ' - NumberOfMessagesPublished' */ readonly alarmName?: string; /** * The description of the alarm. * * @default - This alarm can detect when the number of SNS messages published is too low. * For troubleshooting, check why the publishers are sending less traffic. */ readonly alarmDescription?: string; } /** * Properties for the SnsNumberOfMessagesPublishedAlarm construct. */ export interface SnsNumberOfMessagesPublishedAlarmProps extends SnsNumberOfMessagesPublishedAlarmConfig { /** * The SNS topic for which to create the alarm. */ readonly topic: sns.ITopic; } /** * An alarm that monitors the number of messages published to an SNS topic. * * This alarm helps you proactively monitor and detect significant drops in * notification publishing. This helps you identify potential issues with * your application or business processes, so that you can take appropriate * actions to maintain the expected flow of notifications. You should create * this alarm if you expect your system to have a minimum traffic that it * is serving. * * The alarm is triggered when the number of messages published to the topic * is less than the specified threshold. */ export declare class SnsNumberOfMessagesPublishedAlarm extends cloudwatch.Alarm { constructor(scope: IConstruct, id: string, props: SnsNumberOfMessagesPublishedAlarmProps); } /** * Configuration for the NumberOfNotificationsDelivered alarm. */ export interface SnsNumberOfNotificationsDeliveredAlarmConfig extends SnsAlarmBaseConfig { /** * The value against which the specified statistic is compared. * * The number of messages delivered should be in line with the expected number of * messages produced and the number of consumers. You can also analyze the historical * data, trends and traffic to find the right threshold. */ readonly threshold: number; /** * The alarm name. * * @default - topic.topicName + ' - NumberOfNotificationsDelivered' */ readonly alarmName?: string; /** * The description of the alarm. * * @default - This alarm can detect when the number of SNS messages delivered is too low. * This could be because of unintentional unsubscribing of an endpoint, or because of * an SNS event that causes messages to experience delay. */ readonly alarmDescription?: string; } /** * Properties for the SnsNumberOfNotificationsDeliveredAlarm construct. */ export interface SnsNumberOfNotificationsDeliveredAlarmProps extends SnsNumberOfNotificationsDeliveredAlarmConfig { /** * The SNS topic for which to create the alarm. */ readonly topic: sns.ITopic; } /** * An alarm that monitors the number of notifications delivered by an SNS topic. * * This alarm helps you detect a drop in the volume of messages delivered. * You should create this alarm if you expect your system to have a * minimum traffic that it is serving. * * The alarm is triggered when the number of messages delivered by the topic * is less than the specified threshold. */ export declare class SnsNumberOfNotificationsDeliveredAlarm extends cloudwatch.Alarm { constructor(scope: IConstruct, id: string, props: SnsNumberOfNotificationsDeliveredAlarmProps); } /** * Configuration for the NumberOfNotificationsFailed alarm. */ export interface SnsNumberOfNotificationsFailedAlarmConfig extends SnsAlarmBaseConfig { /** * The value against which the specified statistic is compared. * * The recommended threshold value for this alarm is highly dependent on the * impact of failed notifications. Review the SLAs provided to your end users, * fault tolerance and criticality of notifications and analyze historical data, * and then select a threshold accordingly. The number of notifications failed * should be 0 for topics that have only SQS, Lambda or Firehose subscriptions. */ readonly threshold: number; /** * The alarm name. * * @default - topic.topicName + ' - NumberOfNotificationsFailed' */ readonly alarmName?: string; /** * The description of the alarm. * * @default - This alarm can detect when the number of failed SNS messages is too high. * To troubleshoot failed notifications, enable logging to CloudWatch Logs. Checking * the logs can help you find which subscribers are failing, as well as the status * codes they are returning. */ readonly alarmDescription?: string; } /** * Properties for the SnsNumberOfNotificationsFailedAlarm construct. */ export interface SnsNumberOfNotificationsFailedAlarmProps extends SnsNumberOfNotificationsFailedAlarmConfig { /** * The SNS topic for which to create the alarm. */ readonly topic: sns.ITopic; } /** * An alarm that monitors the number of notifications failed by an SNS topic. * * This alarm helps you proactively find issues with the delivery of notifications * and take appropriate actions to address them. * * The alarm is triggered when the number of messages failed by the topic * is greater than the specified threshold. */ export declare class SnsNumberOfNotificationsFailedAlarm extends cloudwatch.Alarm { constructor(scope: IConstruct, id: string, props: SnsNumberOfNotificationsFailedAlarmProps); } /** * Configuration for the NumberOfNotificationsFilteredOutInvalidAttributes alarm. */ export interface SnsNumberOfNotificationsFilteredOutInvalidAttributesAlarmConfig extends SnsAlarmBaseConfig { /** * The value against which the specified statistic is compared. * * Invalid attributes are almost always a mistake by the publisher. We recommend * to set the threshold to 0 because invalid attributes are not expected in a * healthy system. * * @default 0 */ readonly threshold?: number; /** * The alarm name. * * @default - topic.topicName + ' - NumberOfNotificationsFilteredOut-InvalidAttributes' */ readonly alarmName?: string; /** * The description of the alarm. * * @default - This alarm helps to monitor and resolve potential problems with the publisher or subscribers. * Check if a publisher is publishing messages with invalid attributes or if an inappropriate filter is * applied to a subscriber. You can also analyze CloudWatch Logs to help find the root cause of the issue. */ readonly alarmDescription?: string; } /** * Properties for the SnsNumberOfNotificationsFilteredOutInvalidAttributesAlarm construct. */ export interface SnsNumberOfNotificationsFilteredOutInvalidAttributesAlarmProps extends SnsNumberOfNotificationsFilteredOutInvalidAttributesAlarmConfig { /** * The SNS topic for which to create the alarm. */ readonly topic: sns.ITopic; } /** * An alarm that monitors the number of notifications filtered out due * to invalid attributes. * * The alarm is used to detect if the published messages are not valid or * if inappropriate filters have been applied to a subscriber. * * The alarm is triggered when the number of messages filtered out due to * invalid attributes is greater than the specified threshold. */ export declare class SnsNumberOfNotificationsFilteredOutInvalidAttributesAlarm extends cloudwatch.Alarm { constructor(scope: IConstruct, id: string, props: SnsNumberOfNotificationsFilteredOutInvalidAttributesAlarmProps); } /** * Configuration for the NumberOfNotificationsFilteredOutInvalidMessageBody alarm. */ export interface SnsNumberOfNotificationsFilteredOutInvalidMessageBodyAlarmConfig extends SnsAlarmBaseConfig { /** * The value against which the specified statistic is compared. * * Invalid message bodies are almost always a mistake by the publisher. * We recommend to set the threshold to 0 because invalid message bodies * are not expected in a healthy system. * * @default 0 */ readonly threshold?: number; /** * The alarm name. * * @default - topic.topicName + ' - NumberOfNotificationsFilteredOut-InvalidMessageBody' */ readonly alarmName?: string; /** * The description of the alarm. * * @default - This alarm helps to monitor and resolve potential problems with the * publisher or subscribers. Check if a publisher is publishing messages with * invalid message bodies, or if an inappropriate filter is applied to a subscriber. * You can also analyze CloudWatch Logs to help find the root cause of the issue. */ readonly alarmDescription?: string; } /** * Properties for the SnsNumberOfNotificationsFilteredOutInvalidMessageBodyAlarm construct. */ export interface SnsNumberOfNotificationsFilteredOutInvalidMessageBodyAlarmProps extends SnsNumberOfNotificationsFilteredOutInvalidMessageBodyAlarmConfig { /** * The SNS topic for which to create the alarm. */ readonly topic: sns.ITopic; } /** * An alarm that monitors the number of notifications filtered out due * to invalid message body. * * The alarm is used to detect if the published messages are not valid or * if inappropriate filters have been applied to a subscriber. * * The alarm is triggered when the number of messages filtered out due to * invalid message body is greater than the specified threshold. */ export declare class SnsNumberOfNotificationsFilteredOutInvalidMessageBodyAlarm extends cloudwatch.Alarm { constructor(scope: IConstruct, id: string, props: SnsNumberOfNotificationsFilteredOutInvalidMessageBodyAlarmProps); } /** * Configuration for the NumberOfNotificationsRedrivenToDlq alarm. */ export interface SnsNumberOfNotificationsRedrivenToDlqAlarmConfig extends SnsAlarmBaseConfig { /** * The value against which the specified statistic is compared. * * In a healthy system of any subscriber type, messages should not be moved * to the dead-letter queue. We recommend that you be notified if any messages * land in the queue, so that you can identify and address the root cause, * and potentially redrive the messages in the dead-letter queue to prevent * data loss. * * @default 0 */ readonly threshold?: number; /** * The alarm name. * * @default - topic.topicName + ' - NumberOfNotificationsRedrivenToDlq' */ readonly alarmName?: string; /** * The description of the alarm. * * @default - This alarm helps to monitor the number of messages that are moved to a dead-letter queue. */ readonly alarmDescription?: string; } /** * Properties for the SnsNumberOfNotificationsRedrivenToDlqAlarm construct. */ export interface SnsNumberOfNotificationsRedrivenToDlqAlarmProps extends SnsNumberOfNotificationsRedrivenToDlqAlarmConfig { /** * The SNS topic for which to create the alarm. */ readonly topic: sns.ITopic; } /** * An alarm that monitors the number of notifications redriven * to the dead-letter queue. * * The alarm is used to detect messages that moved to a dead-letter * queue. We recommend that you create this alarm when SNS is coupled * with SQS, Lambda or Firehose. * * The alarm is triggered when the number of messages redriven to the * dead-letter queue is greater than the specified threshold. */ export declare class SnsNumberOfNotificationsRedrivenToDlqAlarm extends cloudwatch.Alarm { constructor(scope: IConstruct, id: string, props: SnsNumberOfNotificationsRedrivenToDlqAlarmProps); } /** * Configuration for the NumberOfNotificationsFailedToRedriveToDlq alarm. */ export interface SnsNumberOfNotificationsFailedToRedriveToDlqAlarmConfig extends SnsAlarmBaseConfig { /** * The value against which the specified statistic is compared. * * It's almost always a mistake if messages can't be moved to the dead-letter queue. * The recommendation for the threshold is 0, meaning all messages that fail processing * must be able to reach the dead-letter queue when the queue has been configured. * * @default 0 */ readonly threshold?: number; /** * The alarm name. * * @default - topic.topicName + ' - NumberOfNotificationsFailedToRedriveToDlq' */ readonly alarmName?: string; /** * The description of the alarm. * * @default - This alarm helps to monitor messages that couldn't be moved to a dead-letter * queue. Check whether your dead-letter queue exists and that it's configured correctly. * Also, verify that SNS has permissions to access the dead-letter queue. Refer to the * dead-letter queue documentation (https://docs.aws.amazon.com/sns/latest/dg/sns-dead-letter-queues.html) * to learn more. */ readonly alarmDescription?: string; } /** * Properties for the SnsNumberOfNotificationsFailedToRedriveToDlqAlarm construct. */ export interface SnsNumberOfNotificationsFailedToRedriveToDlqAlarmProps extends SnsNumberOfNotificationsFailedToRedriveToDlqAlarmConfig { /** * The SNS topic for which to create the alarm. */ readonly topic: sns.ITopic; } /** * An alarm that monitors the number of notifications failed to redrive * to the dead-letter queue. * * The alarm is used to detect messages that couldn't be moved to a dead-letter * queue. * * The alarm is triggered when the number of messages failed to redrive to the * dead-letter queue is greater than the specified threshold. */ export declare class SnsNumberOfNotificationsFailedToRedriveToDlqAlarm extends cloudwatch.Alarm { constructor(scope: IConstruct, id: string, props: SnsNumberOfNotificationsFailedToRedriveToDlqAlarmProps); } export interface SnsRecommendedAlarmsConfig { /** * The default action to take when an alarm is triggered. * * @default - None */ readonly defaultAlarmAction?: cloudwatch.IAlarmAction; /** * The default action to take when an alarm enters the ok state. * * @default - None */ readonly defaultOkAction?: cloudwatch.IAlarmAction; /** * The default action to take when an alarm has insufficient data. * * @default - None */ readonly defaultInsufficientDataAction?: cloudwatch.IAlarmAction; /** * How to handle missing data for this alarm. * * @default TreatMissingData.MISSING */ readonly treatMissingData?: cloudwatch.TreatMissingData; /** * Alarm metrics to exclude from the recommended alarms. * * @default - None */ readonly excludeAlarms?: SnsRecommendedAlarmsMetrics[]; /** * The resources to exclude from the recommended alarms. * * Use a resources id to exclude a specific resource. */ readonly excludeResources?: string[]; /** * The configuration for the NumberOfMessagesPublished alarm. */ readonly configNumberOfMessagesPublishedAlarm: SnsNumberOfMessagesPublishedAlarmConfig; /** * The configuration for the NumberOfNotificationsDelivered alarm. */ readonly configNumberOfNotificationsDeliveredAlarm: SnsNumberOfNotificationsDeliveredAlarmConfig; /** * The configuration for the NumberOfNotificationsFailed alarm. */ readonly configNumberOfNotificationsFailedAlarm: SnsNumberOfNotificationsFailedAlarmConfig; /** * The configuration for the NumberOfNotificationsFilteredOutInvalidAttributes alarm. */ readonly configNumberOfNotificationsFilteredOutInvalidAttributesAlarm?: SnsNumberOfNotificationsFilteredOutInvalidAttributesAlarmConfig; /** * The configuration for the NumberOfNotificationsFilteredOutInvalidMessageBody alarm. */ readonly configNumberOfNotificationsFilteredOutInvalidMessageBodyAlarm?: SnsNumberOfNotificationsFilteredOutInvalidMessageBodyAlarmConfig; /** * The configuration for the NumberOfNotificationsRedrivenToDlq alarm. */ readonly configNumberOfNotificationsRedrivenToDlqAlarm?: SnsNumberOfNotificationsRedrivenToDlqAlarmConfig; /** * The configuration for the NumberOfNotificationsFailedToRedriveToDlq alarm. */ readonly configNumberOfNotificationsFailedToRedriveToDlqAlarm?: SnsNumberOfNotificationsFailedToRedriveToDlqAlarmConfig; } export interface SnsRecommendedAlarmsProps extends SnsRecommendedAlarmsConfig { /** * The SNS topic for which to create the alarms. */ readonly topic: sns.ITopic; } /** * A construct that creates recommended alarms for an SNS topic. * * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SNS */ export declare class SnsRecommendedAlarms extends Construct { /** * The NumberOfMessagesPublished alarm. */ readonly alarmNumberOfMessagesPublished?: SnsNumberOfMessagesPublishedAlarm; /** * The NumberOfNotificationsDelivered alarm. */ readonly alarmNumberOfNotificationsDelivered?: SnsNumberOfNotificationsDeliveredAlarm; /** * The NumberOfNotificationsFailed alarm. */ readonly alarmNumberOfNotificationsFailed?: SnsNumberOfNotificationsFailedAlarm; /** * The NumberOfNotificationsFilteredOutInvalidAttributes alarm. */ readonly alarmNumberOfNotificationsFilteredOutInvalidAttributes?: SnsNumberOfNotificationsFilteredOutInvalidAttributesAlarm; /** * The NumberOfNotificationsFilteredOutInvalidMessageBody alarm. */ readonly alarmNumberOfNotificationsFilteredOutInvalidMessageBody?: SnsNumberOfNotificationsFilteredOutInvalidMessageBodyAlarm; /** * The NumberOfNotificationsRedrivenToDlq alarm. */ readonly alarmNumberOfNotificationsRedrivenToDlq?: SnsNumberOfNotificationsRedrivenToDlqAlarm; /** * The NumberOfNotificationsFailedToRedriveToDlq alarm. */ readonly alarmNumberOfNotificationsFailedToRedriveToDlq?: SnsNumberOfNotificationsFailedToRedriveToDlqAlarm; constructor(scope: Construct, id: string, props: SnsRecommendedAlarmsProps); } /** * An extension of the SNS topic construct that provides helper * methods to create recommended alarms. */ export declare class Topic extends sns.Topic { constructor(scope: Construct, id: string, props?: sns.TopicProps); /** * Creates an alarm for the NumberOfMessagesPublished metric. */ alarmNumberOfMessagesPublished(props: SnsNumberOfMessagesPublishedAlarmConfig): SnsNumberOfMessagesPublishedAlarm; /** * Creates an alarm for the NumberOfNotificationsDelivered metric. */ alarmNumberOfNotificationsDelivered(props: SnsNumberOfNotificationsDeliveredAlarmConfig): SnsNumberOfNotificationsDeliveredAlarm; /** * Creates an alarm for the NumberOfNotificationsFailed metric. */ alarmNumberOfNotificationsFailed(props: SnsNumberOfNotificationsFailedAlarmConfig): SnsNumberOfNotificationsFailedAlarm; /** * Creates an alarm for the NumberOfNotificationsFilteredOutInvalidAttributes metric. */ alarmNumberOfNotificationsFilteredOutInvalidAttributes(props?: SnsNumberOfNotificationsFilteredOutInvalidAttributesAlarmConfig): SnsNumberOfNotificationsFilteredOutInvalidAttributesAlarm; /** * Creates an alarm for the NumberOfNotificationsFilteredOutInvalidMessageBody metric. */ alarmNumberOfNotificationsFilteredOutInvalidMessageBody(props?: SnsNumberOfNotificationsFilteredOutInvalidMessageBodyAlarmConfig): SnsNumberOfNotificationsFilteredOutInvalidMessageBodyAlarm; /** * Creates an alarm for the NumberOfNotificationsRedrivenToDlq metric. */ alarmNumberOfNotificationsRedrivenToDlq(props?: SnsNumberOfNotificationsRedrivenToDlqAlarmConfig): SnsNumberOfNotificationsRedrivenToDlqAlarm; /** * Creates an alarm for the NumberOfNotificationsFailedToRedriveToDlq metric. */ alarmNumberOfNotificationsFailedToRedriveToDlq(props?: SnsNumberOfNotificationsFailedToRedriveToDlqAlarmConfig): SnsNumberOfNotificationsFailedToRedriveToDlqAlarm; /** * Creates recommended alarms for the SNS topic. * * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SNS */ applyRecommendedAlarms(props: SnsRecommendedAlarmsConfig): SnsRecommendedAlarms; } /** * An aspect that applies recommended alarms to SNS topics. * * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SNS */ export declare class SnsRecommendedAlarmsAspect implements IAspect { private readonly props; constructor(props: SnsRecommendedAlarmsConfig); visit(node: IConstruct): void; }