UNPKG

@pulumi/aws

Version:

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

323 lines • 12 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.MetricAlarm = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * 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 */ 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, id, state, opts) { return new MetricAlarm(name, state, { ...opts, id: id }); } /** * 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) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === MetricAlarm.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["actionsEnabled"] = state?.actionsEnabled; resourceInputs["alarmActions"] = state?.alarmActions; resourceInputs["alarmDescription"] = state?.alarmDescription; resourceInputs["arn"] = state?.arn; resourceInputs["comparisonOperator"] = state?.comparisonOperator; resourceInputs["datapointsToAlarm"] = state?.datapointsToAlarm; resourceInputs["dimensions"] = state?.dimensions; resourceInputs["evaluateLowSampleCountPercentiles"] = state?.evaluateLowSampleCountPercentiles; resourceInputs["evaluationPeriods"] = state?.evaluationPeriods; resourceInputs["extendedStatistic"] = state?.extendedStatistic; resourceInputs["insufficientDataActions"] = state?.insufficientDataActions; resourceInputs["metricName"] = state?.metricName; resourceInputs["metricQueries"] = state?.metricQueries; resourceInputs["name"] = state?.name; resourceInputs["namespace"] = state?.namespace; resourceInputs["okActions"] = state?.okActions; resourceInputs["period"] = state?.period; resourceInputs["region"] = state?.region; resourceInputs["statistic"] = state?.statistic; resourceInputs["tags"] = state?.tags; resourceInputs["tagsAll"] = state?.tagsAll; resourceInputs["threshold"] = state?.threshold; resourceInputs["thresholdMetricId"] = state?.thresholdMetricId; resourceInputs["treatMissingData"] = state?.treatMissingData; resourceInputs["unit"] = state?.unit; } else { const args = argsOrState; if (args?.comparisonOperator === undefined && !opts.urn) { throw new Error("Missing required property 'comparisonOperator'"); } if (args?.evaluationPeriods === undefined && !opts.urn) { throw new Error("Missing required property 'evaluationPeriods'"); } resourceInputs["actionsEnabled"] = args?.actionsEnabled; resourceInputs["alarmActions"] = args?.alarmActions; resourceInputs["alarmDescription"] = args?.alarmDescription; resourceInputs["comparisonOperator"] = args?.comparisonOperator; resourceInputs["datapointsToAlarm"] = args?.datapointsToAlarm; resourceInputs["dimensions"] = args?.dimensions; resourceInputs["evaluateLowSampleCountPercentiles"] = args?.evaluateLowSampleCountPercentiles; resourceInputs["evaluationPeriods"] = args?.evaluationPeriods; resourceInputs["extendedStatistic"] = args?.extendedStatistic; resourceInputs["insufficientDataActions"] = args?.insufficientDataActions; resourceInputs["metricName"] = args?.metricName; resourceInputs["metricQueries"] = args?.metricQueries; resourceInputs["name"] = args?.name; resourceInputs["namespace"] = args?.namespace; resourceInputs["okActions"] = args?.okActions; resourceInputs["period"] = args?.period; resourceInputs["region"] = args?.region; resourceInputs["statistic"] = args?.statistic; resourceInputs["tags"] = args?.tags; resourceInputs["threshold"] = args?.threshold; resourceInputs["thresholdMetricId"] = args?.thresholdMetricId; resourceInputs["treatMissingData"] = args?.treatMissingData; resourceInputs["unit"] = args?.unit; resourceInputs["arn"] = undefined /*out*/; resourceInputs["tagsAll"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(MetricAlarm.__pulumiType, name, resourceInputs, opts); } } exports.MetricAlarm = MetricAlarm; /** @internal */ MetricAlarm.__pulumiType = 'aws:cloudwatch/metricAlarm:MetricAlarm'; //# sourceMappingURL=metricAlarm.js.map