Class MetricAlarm
Provides a CloudWatch Metric Alarm resource.
Example Usage
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var foobar = new Aws.CloudWatch.MetricAlarm("foobar", new Aws.CloudWatch.MetricAlarmArgs
{
AlarmDescription = "This metric monitors ec2 cpu utilization",
ComparisonOperator = "GreaterThanOrEqualToThreshold",
EvaluationPeriods = "2",
InsufficientDataActions = {},
MetricName = "CPUUtilization",
Namespace = "AWS/EC2",
Period = "120",
Statistic = "Average",
Threshold = "80",
});
}
}
Example in Conjunction with Scaling Policies
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var batPolicy = new Aws.AutoScaling.Policy("batPolicy", new Aws.AutoScaling.PolicyArgs
{
AdjustmentType = "ChangeInCapacity",
AutoscalingGroupName = aws_autoscaling_group.Bar.Name,
Cooldown = 300,
ScalingAdjustment = 4,
});
var batMetricAlarm = new Aws.CloudWatch.MetricAlarm("batMetricAlarm", new Aws.CloudWatch.MetricAlarmArgs
{
AlarmActions =
{
batPolicy.Arn,
},
AlarmDescription = "This metric monitors ec2 cpu utilization",
ComparisonOperator = "GreaterThanOrEqualToThreshold",
Dimensions =
{
{ "AutoScalingGroupName", aws_autoscaling_group.Bar.Name },
},
EvaluationPeriods = "2",
MetricName = "CPUUtilization",
Namespace = "AWS/EC2",
Period = "120",
Statistic = "Average",
Threshold = "80",
});
}
}
Example with an Expression
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var foobar = new Aws.CloudWatch.MetricAlarm("foobar", new Aws.CloudWatch.MetricAlarmArgs
{
AlarmDescription = "Request error rate has exceeded 10%",
ComparisonOperator = "GreaterThanOrEqualToThreshold",
EvaluationPeriods = "2",
InsufficientDataActions = {},
MetricQueries =
{
new Aws.CloudWatch.Inputs.MetricAlarmMetricQueryArgs
{
Expression = "m2/m1*100",
Id = "e1",
Label = "Error Rate",
ReturnData = "true",
},
new Aws.CloudWatch.Inputs.MetricAlarmMetricQueryArgs
{
Id = "m1",
Metric = new Aws.CloudWatch.Inputs.MetricAlarmMetricQueryMetricArgs
{
Dimensions =
{
{ "LoadBalancer", "app/web" },
},
MetricName = "RequestCount",
Namespace = "AWS/ApplicationELB",
Period = "120",
Stat = "Sum",
Unit = "Count",
},
},
new Aws.CloudWatch.Inputs.MetricAlarmMetricQueryArgs
{
Id = "m2",
Metric = new Aws.CloudWatch.Inputs.MetricAlarmMetricQueryMetricArgs
{
Dimensions =
{
{ "LoadBalancer", "app/web" },
},
MetricName = "HTTPCode_ELB_5XX_Count",
Namespace = "AWS/ApplicationELB",
Period = "120",
Stat = "Sum",
Unit = "Count",
},
},
},
Threshold = "10",
});
}
}
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var xxAnomalyDetection = new Aws.CloudWatch.MetricAlarm("xxAnomalyDetection", new Aws.CloudWatch.MetricAlarmArgs
{
AlarmDescription = "This metric monitors ec2 cpu utilization",
ComparisonOperator = "GreaterThanUpperThreshold",
EvaluationPeriods = "2",
InsufficientDataActions = {},
MetricQueries =
{
new Aws.CloudWatch.Inputs.MetricAlarmMetricQueryArgs
{
Expression = "ANOMALY_DETECTION_BAND(m1)",
Id = "e1",
Label = "CPUUtilization (Expected)",
ReturnData = "true",
},
new Aws.CloudWatch.Inputs.MetricAlarmMetricQueryArgs
{
Id = "m1",
Metric = new Aws.CloudWatch.Inputs.MetricAlarmMetricQueryMetricArgs
{
Dimensions =
{
{ "InstanceId", "i-abc123" },
},
MetricName = "CPUUtilization",
Namespace = "AWS/EC2",
Period = "120",
Stat = "Average",
Unit = "Count",
},
ReturnData = "true",
},
},
ThresholdMetricId = "e1",
});
}
}
Example of monitoring Healthy Hosts on NLB using Target Group and NLB
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var xxxNlbHealthyhosts = new Aws.CloudWatch.MetricAlarm("xxxNlbHealthyhosts", new Aws.CloudWatch.MetricAlarmArgs
{
ComparisonOperator = "LessThanThreshold",
EvaluationPeriods = "1",
MetricName = "HealthyHostCount",
Namespace = "AWS/NetworkELB",
Period = "60",
Statistic = "Average",
Threshold = @var.Logstash_servers_count,
AlarmDescription = "Number of XXXX nodes healthy in Target Group",
ActionsEnabled = "true",
AlarmActions =
{
aws_sns_topic.Sns.Arn,
},
OkActions =
{
aws_sns_topic.Sns.Arn,
},
Dimensions =
{
{ "TargetGroup", aws_lb_target_group.Lb_tg.Arn_suffix },
{ "LoadBalancer", aws_lb.Lb.Arn_suffix },
},
});
}
}
NOTE: You cannot create a metric alarm consisting of both
statisticandextended_statisticparameters. You must choose one or the other
Inherited Members
Namespace: Pulumi.Aws.CloudWatch
Assembly: Pulumi.Aws.dll
Syntax
public class MetricAlarm : CustomResource
Constructors
View SourceMetricAlarm(String, MetricAlarmArgs, CustomResourceOptions)
Create a MetricAlarm resource with the given unique name, arguments, and options.
Declaration
public MetricAlarm(string name, MetricAlarmArgs args, CustomResourceOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The unique name of the resource |
| MetricAlarmArgs | args | The arguments used to populate this resource's properties |
| CustomResourceOptions | options | A bag of options that control this resource's behavior |
Properties
View SourceActionsEnabled
Indicates whether or not actions should be executed during any changes to the alarm's state. Defaults to true.
Declaration
public Output<bool?> ActionsEnabled { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Nullable<System.Boolean>> |
AlarmActions
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).
Declaration
public Output<ImmutableArray<string>> AlarmActions { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Collections.Immutable.ImmutableArray<System.String>> |
AlarmDescription
The description for the alarm.
Declaration
public Output<string> AlarmDescription { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
Arn
The ARN of the cloudwatch metric alarm.
Declaration
public Output<string> Arn { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
ComparisonOperator
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.
Declaration
public Output<string> ComparisonOperator { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
DatapointsToAlarm
The number of datapoints that must be breaching to trigger the alarm.
Declaration
public Output<int?> DatapointsToAlarm { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Nullable<System.Int32>> |
Dimensions
The dimensions for this metric. For the list of available dimensions see the AWS documentation here.
Declaration
public Output<ImmutableDictionary<string, object>> Dimensions { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Collections.Immutable.ImmutableDictionary<System.String, System.Object>> |
EvaluateLowSampleCountPercentiles
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.
Declaration
public Output<string> EvaluateLowSampleCountPercentiles { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
EvaluationPeriods
The number of periods over which data is compared to the specified threshold.
Declaration
public Output<int> EvaluationPeriods { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Int32> |
ExtendedStatistic
The percentile statistic for the metric associated with the alarm. Specify a value between p0.0 and p100.
Declaration
public Output<string> ExtendedStatistic { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
InsufficientDataActions
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).
Declaration
public Output<ImmutableArray<string>> InsufficientDataActions { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Collections.Immutable.ImmutableArray<System.String>> |
MetricName
The name for this metric. See docs for supported metrics.
Declaration
public Output<string> MetricName { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
MetricQueries
Enables you to create an alarm based on a metric math expression. You may specify at most 20.
Declaration
public Output<ImmutableArray<MetricAlarmMetricQuery>> MetricQueries { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Collections.Immutable.ImmutableArray<MetricAlarmMetricQuery>> |
Name
The descriptive name for the alarm. This name must be unique within the user's AWS account
Declaration
public Output<string> Name { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
Namespace
The namespace for this metric. See docs for the list of namespaces. See docs for supported metrics.
Declaration
public Output<string> Namespace { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
OkActions
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).
Declaration
public Output<ImmutableArray<string>> OkActions { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Collections.Immutable.ImmutableArray<System.String>> |
Period
The period in seconds over which the specified stat is applied.
Declaration
public Output<int?> Period { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Nullable<System.Int32>> |
Statistic
The statistic to apply to the alarm's associated metric.
Either of the following is supported: SampleCount, Average, Sum, Minimum, Maximum
Declaration
public Output<string> Statistic { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
Tags
A map of tags to assign to the resource.
Declaration
public Output<ImmutableDictionary<string, object>> Tags { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Collections.Immutable.ImmutableDictionary<System.String, System.Object>> |
Threshold
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.
Declaration
public Output<double?> Threshold { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Nullable<System.Double>> |
ThresholdMetricId
If this is an alarm based on an anomaly detection model, make this value match the ID of the ANOMALY_DETECTION_BAND function.
Declaration
public Output<string> ThresholdMetricId { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
TreatMissingData
Sets how this alarm is to handle missing data points. The following values are supported: missing, ignore, breaching and notBreaching. Defaults to missing.
Declaration
public Output<string> TreatMissingData { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
Unit
The unit for this metric.
Declaration
public Output<string> Unit { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
Methods
View SourceGet(String, Input<String>, MetricAlarmState, CustomResourceOptions)
Get an existing MetricAlarm resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
Declaration
public static MetricAlarm Get(string name, Input<string> id, MetricAlarmState state = null, CustomResourceOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The unique name of the resulting resource. |
| Input<System.String> | id | The unique provider ID of the resource to lookup. |
| MetricAlarmState | state | Any extra arguments used during the lookup. |
| CustomResourceOptions | options | A bag of options that control this resource's behavior |
Returns
| Type | Description |
|---|---|
| MetricAlarm |