UNPKG

@pulumi/aws

Version:

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.

604 lines (603 loc) • 27.2 kB
import * as pulumi from "@pulumi/pulumi"; import * as inputs from "../types/input"; import * as outputs from "../types/output"; import { Topic } from "../sns"; /** * Provides a CloudWatch Metric Alarm resource. * * ## Example Usage * * ### Basic Usage * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const foobar = new aws.cloudwatch.MetricAlarm("foobar", { * name: "test-foobar5", * comparisonOperator: "GreaterThanOrEqualToThreshold", * evaluationPeriods: 2, * metricName: "CPUUtilization", * namespace: "AWS/EC2", * period: 120, * statistic: "Average", * threshold: 80, * alarmDescription: "This metric monitors ec2 cpu utilization", * insufficientDataActions: [], * }); * ``` * * ### With Scaling Policies * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const bat = new aws.autoscaling.Policy("bat", { * name: "foobar3-test", * scalingAdjustment: 4, * adjustmentType: "ChangeInCapacity", * cooldown: 300, * autoscalingGroupName: bar.name, * }); * const batMetricAlarm = new aws.cloudwatch.MetricAlarm("bat", { * name: "test-foobar5", * comparisonOperator: "GreaterThanOrEqualToThreshold", * evaluationPeriods: 2, * metricName: "CPUUtilization", * namespace: "AWS/EC2", * period: 120, * statistic: "Average", * threshold: 80, * dimensions: { * AutoScalingGroupName: bar.name, * }, * alarmDescription: "This metric monitors ec2 cpu utilization", * alarmActions: [bat.arn], * }); * ``` * * ### With a Metrics Math Expression * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const foobar = new aws.cloudwatch.MetricAlarm("foobar", { * name: "test-foobar", * comparisonOperator: "GreaterThanOrEqualToThreshold", * evaluationPeriods: 2, * threshold: 10, * alarmDescription: "Request error rate has exceeded 10%", * insufficientDataActions: [], * metricQueries: [ * { * id: "e1", * expression: "m2/m1*100", * label: "Error Rate", * returnData: true, * }, * { * id: "m1", * metric: { * metricName: "RequestCount", * namespace: "AWS/ApplicationELB", * period: 120, * stat: "Sum", * unit: "Count", * dimensions: { * LoadBalancer: "app/web", * }, * }, * }, * { * id: "m2", * metric: { * metricName: "HTTPCode_ELB_5XX_Count", * namespace: "AWS/ApplicationELB", * period: 120, * stat: "Sum", * unit: "Count", * dimensions: { * LoadBalancer: "app/web", * }, * }, * }, * ], * }); * ``` * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const xxAnomalyDetection = new aws.cloudwatch.MetricAlarm("xx_anomaly_detection", { * name: "test-foobar", * comparisonOperator: "GreaterThanUpperThreshold", * evaluationPeriods: 2, * thresholdMetricId: "e1", * alarmDescription: "This metric monitors ec2 cpu utilization", * insufficientDataActions: [], * metricQueries: [ * { * id: "e1", * returnData: true, * expression: "ANOMALY_DETECTION_BAND(m1)", * label: "CPUUtilization (Expected)", * }, * { * id: "m1", * returnData: true, * metric: { * metricName: "CPUUtilization", * namespace: "AWS/EC2", * period: 120, * stat: "Average", * unit: "Count", * dimensions: { * InstanceId: "i-abc123", * }, * }, * }, * ], * }); * ``` * * ### With a Metrics Insights Query * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.cloudwatch.MetricAlarm("example", { * name: "example-alarm", * alarmDescription: "Triggers if the smallest per-instance maximum load during the evaluation period exceeds the threshold", * comparisonOperator: "GreaterThanThreshold", * evaluationPeriods: 1, * threshold: 0.6, * treatMissingData: "notBreaching", * metricQueries: [{ * id: "q1", * expression: `SELECT * MAX(DBLoadRelativeToNumVCPUs) * FROM SCHEMA(\\"AWS/RDS\\", DBInstanceIdentifier) * WHERE DBInstanceIdentifier != 'example-rds-instance' * GROUP BY DBInstanceIdentifier * ORDER BY MIN() ASC * LIMIT 1 * `, * period: 60, * returnData: true, * label: "Max DB Load of the Least-Loaded RDS Instance", * }], * }); * ``` * * ### Monitoring Healthy NLB Hosts with Target Group and NLB * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const nlbHealthyhosts = new aws.cloudwatch.MetricAlarm("nlb_healthyhosts", { * name: "alarmname", * comparisonOperator: "LessThanThreshold", * evaluationPeriods: 1, * metricName: "HealthyHostCount", * namespace: "AWS/NetworkELB", * period: 60, * statistic: "Average", * threshold: logstashServersCount, * alarmDescription: "Number of healthy nodes in Target Group", * actionsEnabled: true, * alarmActions: [sns.arn], * okActions: [sns.arn], * dimensions: { * TargetGroup: lb_tg.arnSuffix, * LoadBalancer: lb.arnSuffix, * }, * }); * ``` * * > **NOTE:** You cannot create a metric alarm consisting of both `statistic` and `extendedStatistic` parameters. * You must choose one or the other. * * ## Import * * ### Identity Schema * * #### Required * * * `alarm_name` (String) Name of the CloudWatch metric alarm. * * #### Optional * * * `account_id` (String) AWS Account where this resource is managed. * * * `region` (String) Region where this resource is managed. * * Using `pulumi import`, import CloudWatch Metric Alarm using the `alarm_name`. For example: * * console * * % pulumi import aws_cloudwatch_metric_alarm.example alarm-12345 */ export declare class MetricAlarm extends pulumi.CustomResource { /** * Get an existing MetricAlarm resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param state Any extra arguments used during the lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name: string, id: pulumi.Input<pulumi.ID>, state?: MetricAlarmState, opts?: pulumi.CustomResourceOptions): MetricAlarm; /** * Returns true if the given object is an instance of MetricAlarm. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj: any): obj is MetricAlarm; /** * Indicates whether or not actions should be executed during any changes to the alarm's state. Defaults to `true`. */ readonly actionsEnabled: pulumi.Output<boolean | undefined>; /** * The list of actions to execute when this alarm transitions into an ALARM state from any other state. Each action is specified as an Amazon Resource Name (ARN). */ readonly alarmActions: pulumi.Output<string[] | undefined>; /** * The description for the alarm. */ readonly alarmDescription: pulumi.Output<string | undefined>; /** * The ARN of the CloudWatch Metric Alarm. */ readonly arn: pulumi.Output<string>; /** * The arithmetic operation to use when comparing the specified Statistic and Threshold. The specified Statistic value is used as the first operand. Either of the following is supported: `GreaterThanOrEqualToThreshold`, `GreaterThanThreshold`, `LessThanThreshold`, `LessThanOrEqualToThreshold`. Additionally, the values `LessThanLowerOrGreaterThanUpperThreshold`, `LessThanLowerThreshold`, and `GreaterThanUpperThreshold` are used only for alarms based on anomaly detection models. */ readonly comparisonOperator: pulumi.Output<string>; /** * The number of data points that must be breaching to trigger the alarm. */ readonly datapointsToAlarm: pulumi.Output<number | undefined>; /** * The dimensions for the alarm's associated metric. For the list of available dimensions see the AWS documentation [here](http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html). */ readonly dimensions: pulumi.Output<{ [key: string]: string; } | undefined>; /** * Used only for alarms based on percentiles. * If you specify `ignore`, the alarm state will not change during periods with too few data points to be statistically significant. * If you specify `evaluate` or omit this parameter, the alarm will always be evaluated and possibly change state no matter how many data points are available. * The following values are supported: `ignore`, and `evaluate`. */ readonly evaluateLowSampleCountPercentiles: pulumi.Output<string>; /** * The number of periods over which data is compared to the specified threshold. */ readonly evaluationPeriods: pulumi.Output<number>; /** * The percentile statistic for the metric associated with the alarm. Specify a value between p0.0 and p100. */ readonly extendedStatistic: pulumi.Output<string | undefined>; /** * The list of actions to execute when this alarm transitions into an INSUFFICIENT_DATA state from any other state. Each action is specified as an Amazon Resource Name (ARN). */ readonly insufficientDataActions: pulumi.Output<string[] | undefined>; /** * The name for the alarm's associated metric. * See docs for [supported metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html). */ readonly metricName: pulumi.Output<string | undefined>; /** * Enables you to create an alarm based on a metric math expression. You may specify at most 20. */ readonly metricQueries: pulumi.Output<outputs.cloudwatch.MetricAlarmMetricQuery[] | undefined>; /** * The descriptive name for the alarm. This name must be unique within the user's AWS account */ readonly name: pulumi.Output<string>; /** * The namespace for the alarm's associated metric. See docs for the [list of namespaces](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/aws-namespaces.html). * See docs for [supported metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html). */ readonly namespace: pulumi.Output<string | undefined>; /** * The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Name (ARN). */ readonly okActions: pulumi.Output<string[] | undefined>; /** * The period in seconds over which the specified `statistic` is applied. * Valid values are `10`, `20`, `30`, or any multiple of `60`. */ readonly period: pulumi.Output<number | undefined>; /** * Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration. */ readonly region: pulumi.Output<string>; /** * The statistic to apply to the alarm's associated metric. * Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum` */ readonly statistic: pulumi.Output<string | undefined>; /** * A map of tags to assign to the resource. .If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level. * * See [related part of AWS Docs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html) * for details about valid values. * * > **NOTE:** If you specify at least one `metricQuery`, you may not specify a `metricName`, `namespace`, `period` or `statistic`. If you do not specify a `metricQuery`, you must specify each of these (although you may use `extendedStatistic` instead of `statistic`). */ readonly tags: pulumi.Output<{ [key: string]: string; } | undefined>; /** * A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block. */ readonly tagsAll: pulumi.Output<{ [key: string]: string; }>; /** * The value against which the specified statistic is compared. This parameter is required for alarms based on static thresholds, but should not be used for alarms based on anomaly detection models. */ readonly threshold: pulumi.Output<number | undefined>; /** * If this is an alarm based on an anomaly detection model, make this value match the ID of the ANOMALY_DETECTION_BAND function. */ readonly thresholdMetricId: pulumi.Output<string | undefined>; /** * Sets how this alarm is to handle missing data points. The following values are supported: `missing`, `ignore`, `breaching` and `notBreaching`. Defaults to `missing`. */ readonly treatMissingData: pulumi.Output<string | undefined>; /** * The unit for the alarm's associated metric. */ readonly unit: pulumi.Output<string | undefined>; /** * Create a MetricAlarm resource with the given unique name, arguments, and options. * * @param name The _unique_ name of the resource. * @param args The arguments to use to populate this resource's properties. * @param opts A bag of options that control this resource's behavior. */ constructor(name: string, args: MetricAlarmArgs, opts?: pulumi.CustomResourceOptions); } /** * Input properties used for looking up and filtering MetricAlarm resources. */ export interface MetricAlarmState { /** * Indicates whether or not actions should be executed during any changes to the alarm's state. Defaults to `true`. */ actionsEnabled?: pulumi.Input<boolean>; /** * The list of actions to execute when this alarm transitions into an ALARM state from any other state. Each action is specified as an Amazon Resource Name (ARN). */ alarmActions?: pulumi.Input<pulumi.Input<string | Topic>[]>; /** * The description for the alarm. */ alarmDescription?: pulumi.Input<string>; /** * The ARN of the CloudWatch Metric Alarm. */ arn?: pulumi.Input<string>; /** * The arithmetic operation to use when comparing the specified Statistic and Threshold. The specified Statistic value is used as the first operand. Either of the following is supported: `GreaterThanOrEqualToThreshold`, `GreaterThanThreshold`, `LessThanThreshold`, `LessThanOrEqualToThreshold`. Additionally, the values `LessThanLowerOrGreaterThanUpperThreshold`, `LessThanLowerThreshold`, and `GreaterThanUpperThreshold` are used only for alarms based on anomaly detection models. */ comparisonOperator?: pulumi.Input<string>; /** * The number of data points that must be breaching to trigger the alarm. */ datapointsToAlarm?: pulumi.Input<number>; /** * The dimensions for the alarm's associated metric. For the list of available dimensions see the AWS documentation [here](http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html). */ dimensions?: pulumi.Input<{ [key: string]: pulumi.Input<string>; }>; /** * Used only for alarms based on percentiles. * If you specify `ignore`, the alarm state will not change during periods with too few data points to be statistically significant. * If you specify `evaluate` or omit this parameter, the alarm will always be evaluated and possibly change state no matter how many data points are available. * The following values are supported: `ignore`, and `evaluate`. */ evaluateLowSampleCountPercentiles?: pulumi.Input<string>; /** * The number of periods over which data is compared to the specified threshold. */ evaluationPeriods?: pulumi.Input<number>; /** * The percentile statistic for the metric associated with the alarm. Specify a value between p0.0 and p100. */ extendedStatistic?: pulumi.Input<string>; /** * The list of actions to execute when this alarm transitions into an INSUFFICIENT_DATA state from any other state. Each action is specified as an Amazon Resource Name (ARN). */ insufficientDataActions?: pulumi.Input<pulumi.Input<string | Topic>[]>; /** * The name for the alarm's associated metric. * See docs for [supported metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html). */ metricName?: pulumi.Input<string>; /** * Enables you to create an alarm based on a metric math expression. You may specify at most 20. */ metricQueries?: pulumi.Input<pulumi.Input<inputs.cloudwatch.MetricAlarmMetricQuery>[]>; /** * The descriptive name for the alarm. This name must be unique within the user's AWS account */ name?: pulumi.Input<string>; /** * The namespace for the alarm's associated metric. See docs for the [list of namespaces](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/aws-namespaces.html). * See docs for [supported metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html). */ namespace?: pulumi.Input<string>; /** * The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Name (ARN). */ okActions?: pulumi.Input<pulumi.Input<string | Topic>[]>; /** * The period in seconds over which the specified `statistic` is applied. * Valid values are `10`, `20`, `30`, or any multiple of `60`. */ period?: pulumi.Input<number>; /** * Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration. */ region?: pulumi.Input<string>; /** * The statistic to apply to the alarm's associated metric. * Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum` */ statistic?: pulumi.Input<string>; /** * A map of tags to assign to the resource. .If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level. * * See [related part of AWS Docs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html) * for details about valid values. * * > **NOTE:** If you specify at least one `metricQuery`, you may not specify a `metricName`, `namespace`, `period` or `statistic`. If you do not specify a `metricQuery`, you must specify each of these (although you may use `extendedStatistic` instead of `statistic`). */ tags?: pulumi.Input<{ [key: string]: pulumi.Input<string>; }>; /** * A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block. */ tagsAll?: pulumi.Input<{ [key: string]: pulumi.Input<string>; }>; /** * The value against which the specified statistic is compared. This parameter is required for alarms based on static thresholds, but should not be used for alarms based on anomaly detection models. */ threshold?: pulumi.Input<number>; /** * If this is an alarm based on an anomaly detection model, make this value match the ID of the ANOMALY_DETECTION_BAND function. */ thresholdMetricId?: pulumi.Input<string>; /** * Sets how this alarm is to handle missing data points. The following values are supported: `missing`, `ignore`, `breaching` and `notBreaching`. Defaults to `missing`. */ treatMissingData?: pulumi.Input<string>; /** * The unit for the alarm's associated metric. */ unit?: pulumi.Input<string>; } /** * The set of arguments for constructing a MetricAlarm resource. */ export interface MetricAlarmArgs { /** * Indicates whether or not actions should be executed during any changes to the alarm's state. Defaults to `true`. */ actionsEnabled?: pulumi.Input<boolean>; /** * The list of actions to execute when this alarm transitions into an ALARM state from any other state. Each action is specified as an Amazon Resource Name (ARN). */ alarmActions?: pulumi.Input<pulumi.Input<string | Topic>[]>; /** * The description for the alarm. */ alarmDescription?: pulumi.Input<string>; /** * The arithmetic operation to use when comparing the specified Statistic and Threshold. The specified Statistic value is used as the first operand. Either of the following is supported: `GreaterThanOrEqualToThreshold`, `GreaterThanThreshold`, `LessThanThreshold`, `LessThanOrEqualToThreshold`. Additionally, the values `LessThanLowerOrGreaterThanUpperThreshold`, `LessThanLowerThreshold`, and `GreaterThanUpperThreshold` are used only for alarms based on anomaly detection models. */ comparisonOperator: pulumi.Input<string>; /** * The number of data points that must be breaching to trigger the alarm. */ datapointsToAlarm?: pulumi.Input<number>; /** * The dimensions for the alarm's associated metric. For the list of available dimensions see the AWS documentation [here](http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html). */ dimensions?: pulumi.Input<{ [key: string]: pulumi.Input<string>; }>; /** * Used only for alarms based on percentiles. * If you specify `ignore`, the alarm state will not change during periods with too few data points to be statistically significant. * If you specify `evaluate` or omit this parameter, the alarm will always be evaluated and possibly change state no matter how many data points are available. * The following values are supported: `ignore`, and `evaluate`. */ evaluateLowSampleCountPercentiles?: pulumi.Input<string>; /** * The number of periods over which data is compared to the specified threshold. */ evaluationPeriods: pulumi.Input<number>; /** * The percentile statistic for the metric associated with the alarm. Specify a value between p0.0 and p100. */ extendedStatistic?: pulumi.Input<string>; /** * The list of actions to execute when this alarm transitions into an INSUFFICIENT_DATA state from any other state. Each action is specified as an Amazon Resource Name (ARN). */ insufficientDataActions?: pulumi.Input<pulumi.Input<string | Topic>[]>; /** * The name for the alarm's associated metric. * See docs for [supported metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html). */ metricName?: pulumi.Input<string>; /** * Enables you to create an alarm based on a metric math expression. You may specify at most 20. */ metricQueries?: pulumi.Input<pulumi.Input<inputs.cloudwatch.MetricAlarmMetricQuery>[]>; /** * The descriptive name for the alarm. This name must be unique within the user's AWS account */ name?: pulumi.Input<string>; /** * The namespace for the alarm's associated metric. See docs for the [list of namespaces](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/aws-namespaces.html). * See docs for [supported metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html). */ namespace?: pulumi.Input<string>; /** * The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Name (ARN). */ okActions?: pulumi.Input<pulumi.Input<string | Topic>[]>; /** * The period in seconds over which the specified `statistic` is applied. * Valid values are `10`, `20`, `30`, or any multiple of `60`. */ period?: pulumi.Input<number>; /** * Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration. */ region?: pulumi.Input<string>; /** * The statistic to apply to the alarm's associated metric. * Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum` */ statistic?: pulumi.Input<string>; /** * A map of tags to assign to the resource. .If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level. * * See [related part of AWS Docs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html) * for details about valid values. * * > **NOTE:** If you specify at least one `metricQuery`, you may not specify a `metricName`, `namespace`, `period` or `statistic`. If you do not specify a `metricQuery`, you must specify each of these (although you may use `extendedStatistic` instead of `statistic`). */ tags?: pulumi.Input<{ [key: string]: pulumi.Input<string>; }>; /** * The value against which the specified statistic is compared. This parameter is required for alarms based on static thresholds, but should not be used for alarms based on anomaly detection models. */ threshold?: pulumi.Input<number>; /** * If this is an alarm based on an anomaly detection model, make this value match the ID of the ANOMALY_DETECTION_BAND function. */ thresholdMetricId?: pulumi.Input<string>; /** * Sets how this alarm is to handle missing data points. The following values are supported: `missing`, `ignore`, `breaching` and `notBreaching`. Defaults to `missing`. */ treatMissingData?: pulumi.Input<string>; /** * The unit for the alarm's associated metric. */ unit?: pulumi.Input<string>; }