0

我猜 PutMetricAlarm 是解决方案。 http://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html

我试过这个:

Dimension instance = new Dimension();
instance.Name = "InstanceId";
instance.Value = "<i-02e1d855>";
PutMetricAlarmRequest sample =new PutMetricAlarmRequest();
sample.Dimensions.Add(instance);
sample.AlarmName = "SSample";
sample.ComparisonOperator = "LessThanThreshold";
sample.Threshold = .10;
sample.Statistic = "Average";
sample.Period = 300;
sample.EvaluationPeriods = 3;
sample.MetricName = "Metric Name";
sample.Namespace = "name space";
sample.Unit="Percent";
PutMetricAlarmResponse sampleres = cloudwatch.PutMetricAlarm(sample);

但什么也没发生。我做错什么了吗?以及如何添加 AlarmActions?当警报触发时,这将终止我的实例。

请帮忙。谢谢

谢谢。

4

1 回答 1

0

你必须添加这两行

PutMetricAlarmRequest alarmreq=new PutMetricAlarmRequest()
    .withActionsEnabled(true)
    .withAlarmActions("arn:aws:automate:us-east-1:ec2:stop");

//这会停止请求中的实例

于 2013-10-14T19:28:46.387 回答