@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
279 lines • 11.7 kB
JavaScript
"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
*
* ```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: [],
* });
* ```
*
* ## Example in Conjunction 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],
* });
* ```
*
* ## Example with an 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",
* },
* },
* },
* ],
* });
* ```
*
* ## Example of monitoring Healthy Hosts on NLB using 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
*
* Using `pulumi import`, import CloudWatch Metric Alarm using the `alarm_name`. For example:
*
* ```sh
* $ pulumi import aws:cloudwatch/metricAlarm:MetricAlarm test 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, Object.assign(Object.assign({}, 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 ? state.actionsEnabled : undefined;
resourceInputs["alarmActions"] = state ? state.alarmActions : undefined;
resourceInputs["alarmDescription"] = state ? state.alarmDescription : undefined;
resourceInputs["arn"] = state ? state.arn : undefined;
resourceInputs["comparisonOperator"] = state ? state.comparisonOperator : undefined;
resourceInputs["datapointsToAlarm"] = state ? state.datapointsToAlarm : undefined;
resourceInputs["dimensions"] = state ? state.dimensions : undefined;
resourceInputs["evaluateLowSampleCountPercentiles"] = state ? state.evaluateLowSampleCountPercentiles : undefined;
resourceInputs["evaluationPeriods"] = state ? state.evaluationPeriods : undefined;
resourceInputs["extendedStatistic"] = state ? state.extendedStatistic : undefined;
resourceInputs["insufficientDataActions"] = state ? state.insufficientDataActions : undefined;
resourceInputs["metricName"] = state ? state.metricName : undefined;
resourceInputs["metricQueries"] = state ? state.metricQueries : undefined;
resourceInputs["name"] = state ? state.name : undefined;
resourceInputs["namespace"] = state ? state.namespace : undefined;
resourceInputs["okActions"] = state ? state.okActions : undefined;
resourceInputs["period"] = state ? state.period : undefined;
resourceInputs["region"] = state ? state.region : undefined;
resourceInputs["statistic"] = state ? state.statistic : undefined;
resourceInputs["tags"] = state ? state.tags : undefined;
resourceInputs["tagsAll"] = state ? state.tagsAll : undefined;
resourceInputs["threshold"] = state ? state.threshold : undefined;
resourceInputs["thresholdMetricId"] = state ? state.thresholdMetricId : undefined;
resourceInputs["treatMissingData"] = state ? state.treatMissingData : undefined;
resourceInputs["unit"] = state ? state.unit : undefined;
}
else {
const args = argsOrState;
if ((!args || args.comparisonOperator === undefined) && !opts.urn) {
throw new Error("Missing required property 'comparisonOperator'");
}
if ((!args || args.evaluationPeriods === undefined) && !opts.urn) {
throw new Error("Missing required property 'evaluationPeriods'");
}
resourceInputs["actionsEnabled"] = args ? args.actionsEnabled : undefined;
resourceInputs["alarmActions"] = args ? args.alarmActions : undefined;
resourceInputs["alarmDescription"] = args ? args.alarmDescription : undefined;
resourceInputs["comparisonOperator"] = args ? args.comparisonOperator : undefined;
resourceInputs["datapointsToAlarm"] = args ? args.datapointsToAlarm : undefined;
resourceInputs["dimensions"] = args ? args.dimensions : undefined;
resourceInputs["evaluateLowSampleCountPercentiles"] = args ? args.evaluateLowSampleCountPercentiles : undefined;
resourceInputs["evaluationPeriods"] = args ? args.evaluationPeriods : undefined;
resourceInputs["extendedStatistic"] = args ? args.extendedStatistic : undefined;
resourceInputs["insufficientDataActions"] = args ? args.insufficientDataActions : undefined;
resourceInputs["metricName"] = args ? args.metricName : undefined;
resourceInputs["metricQueries"] = args ? args.metricQueries : undefined;
resourceInputs["name"] = args ? args.name : undefined;
resourceInputs["namespace"] = args ? args.namespace : undefined;
resourceInputs["okActions"] = args ? args.okActions : undefined;
resourceInputs["period"] = args ? args.period : undefined;
resourceInputs["region"] = args ? args.region : undefined;
resourceInputs["statistic"] = args ? args.statistic : undefined;
resourceInputs["tags"] = args ? args.tags : undefined;
resourceInputs["threshold"] = args ? args.threshold : undefined;
resourceInputs["thresholdMetricId"] = args ? args.thresholdMetricId : undefined;
resourceInputs["treatMissingData"] = args ? args.treatMissingData : undefined;
resourceInputs["unit"] = args ? args.unit : undefined;
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