我猜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?当警报触发时,它将终止我的实例。
请帮忙。 感谢
感谢。
答案 0 :(得分:0)
你必须添加这两行
PutMetricAlarmRequest alarmreq=new PutMetricAlarmRequest()
.withActionsEnabled(true)
.withAlarmActions("arn:aws:automate:us-east-1:ec2:stop");
//这会停止请求中的实例