[英]Setting CloudWatch Alarm for multiple instances
我正在從Amazon CLI配置實例的警報。 例如,當CPU閑置5分鍾時觸發通知。 但我想為很多實例設置此警報。
使用此Bash腳本,我為一個實例創建了一個警報:
aws cloudwatch put-metric-alarm --alarm-name cpu-mon --alarm-description "Alarm when CPU exceeds 70 percent" --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 300 --threshold 70 --comparison-operator GreaterThanThreshold --dimensions "Name=InstanceId,Value=i-12345678" --evaluation-periods 2 --alarm-actions arn:aws:sns:us-east-1:111122223333:MyTopic --unit Percent
因此,我看不到如何使用此腳本來選擇另一個實例,或者最終在該腳本上循環以選擇另一個實例。
如果您有實例ID的列表,則要為其創建警報,可以執行以下操作:
#!/bin/bash
instances=(instanceId1 instanceId2 etc)
for i in "${instances[@]}"; do
aws cloudwatch put-metric-alarm \
--alarm-name cpu-mon-${i} \
--alarm-description "Alarm when CPU exceeds 70 percent" \
--metric-name CPUUtilization \
--namespace AWS/EC2 \
--statistic Average \
--period 300 \
--threshold 70 \
--comparison-operator GreaterThanThreshold \
--dimensions "Name=InstanceId,Value=${i}" \
--evaluation-periods 2 \
--alarm-actions arn:aws:sns:us-east-1:111122223333:MyTopic \
--unit Percent
done
您還可以最初使用AWS CLI根據標簽,實例名稱等獲取實例ID,然后使用它們沿相同的行創建警報。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.