使用 AWSCLI 设置 AWS cloudwatch diskspaceavailable 警报
AWS cloudwatch diskspaceavailable alarm setup using AWSCLI
我已经设置了一个 cron 作业来将 diskspaceavailable 发送到 cloudwatch 指标,但是当我尝试为 diskspaceavailable 创建 cloudwatch 警报时,由于我在创建闹钟。
磁盘空间可用设置命令
sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA --enablerepo="rhui-REGION-rhel-server-optional" -y
sudo yum install wget zip unzip -y
mkdir /tmp/cloudwatch
sudo wget -P /tmp/cloudwatch https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip
unzip /tmp/cloudwatch/CloudWatchMonitoringScripts-1.2.1.zip
rm -rf /tmp/cloudwatch/CloudWatchMonitoringScripts-1.2.1.zip
cp ~/.aws/credentials /tmp/cloudwatch/aws-scripts-mon/awscreds.conf
sed -i '1d' /tmp/cloudwatch/aws-scripts-mon/awscreds.conf
grep '*/5 * * * * /tmp/cloudwatch/aws-scripts-mon/mon-put-instance-data.pl --disk-path=/ --disk-space-avail --disk-space-used --disk-space-units=gigabytes --from-cron' /etc/crontab || echo '*/5 * * * * /tmp/cloudwatch/aws-scripts-mon/mon-put-instance-data.pl --disk-path=/ --disk-space-avail --disk-space-used --disk-space-units=gigabytes --from-cron' > /etc/crontab
使用什么尺寸才合适?
ARN_OF_SNS_TOPIC="arn:aws:sns:us-east-1::cloudwatch"
CPU_USAGE=50
DISKSPACE_AVAILABLE=20
aws cloudwatch put-metric-alarm ${DRYRUN}\
--alarm-name "${HN}-diskspaceavailable"\
--alarm-description "Alarm when disk space less that 20GB"\
--actions-enabled\
--ok-actions "${ARN_OF_SNS_TOPIC}"\
--alarm-actions "${ARN_OF_SNS_TOPIC}"\
--insufficient-data-actions "${ARN_OF_SNS_TOPIC}"\
--metric-name DiskSpaceAvailable\
--namespace System/Linux\
--statistic Average\
--dimensions Name=InstanceId,Value=${INSTANCE_ID}, Name=Filesystem\
--period 300\
--threshold ${DISKSPACE_AVAILABLE}\
--comparison-operator LessThanThreshold\
--evaluation-periods 1\
--unit Gigabytes
我首先看到的是您缺少文件系统维度的值。应该是这样的:
--dimensions Name=InstanceId,Value=${INSTANCE_ID}, Name=Filesystem,Value=SOMETHING\
您可以在 CloudWatch 指标控制台中查看维度。将指标添加到图表时,您可以将鼠标悬停在“详细信息”列上并查看所有维度。
Filesystem_value=$(df -h / | tail -1 | awk '{print }')
aws cloudwatch put-metric-alarm ${DRYRUN}\
--alarm-name "${HN}-diskspaceavailable"\
--alarm-description "Alarm when disk space less that 20GB"\
--actions-enabled\
--ok-actions "${ARN_OF_SNS_TOPIC}"\
--alarm-actions "${ARN_OF_SNS_TOPIC}"\
--insufficient-data-actions "${ARN_OF_SNS_TOPIC}"\
--metric-name DiskSpaceAvailable\
--namespace System/Linux\
--statistic Average\
--dimensions Name=Filesystem,Value=${Filesystem_value} Name=InstanceId,Value=${INSTANCE_ID} Name=MountPath,Value=/\
--period 300\
--threshold ${DISKSPACE_AVAILABLE}\
--comparison-operator LessThanThreshold\
--evaluation-periods 1
# --unit Gigabytes
echo 'cloudwatch disk space available alarm has been created'
echo
我已经设置了一个 cron 作业来将 diskspaceavailable 发送到 cloudwatch 指标,但是当我尝试为 diskspaceavailable 创建 cloudwatch 警报时,由于我在创建闹钟。
磁盘空间可用设置命令
sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA --enablerepo="rhui-REGION-rhel-server-optional" -y
sudo yum install wget zip unzip -y
mkdir /tmp/cloudwatch
sudo wget -P /tmp/cloudwatch https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip
unzip /tmp/cloudwatch/CloudWatchMonitoringScripts-1.2.1.zip
rm -rf /tmp/cloudwatch/CloudWatchMonitoringScripts-1.2.1.zip
cp ~/.aws/credentials /tmp/cloudwatch/aws-scripts-mon/awscreds.conf
sed -i '1d' /tmp/cloudwatch/aws-scripts-mon/awscreds.conf
grep '*/5 * * * * /tmp/cloudwatch/aws-scripts-mon/mon-put-instance-data.pl --disk-path=/ --disk-space-avail --disk-space-used --disk-space-units=gigabytes --from-cron' /etc/crontab || echo '*/5 * * * * /tmp/cloudwatch/aws-scripts-mon/mon-put-instance-data.pl --disk-path=/ --disk-space-avail --disk-space-used --disk-space-units=gigabytes --from-cron' > /etc/crontab
使用什么尺寸才合适?
ARN_OF_SNS_TOPIC="arn:aws:sns:us-east-1::cloudwatch"
CPU_USAGE=50
DISKSPACE_AVAILABLE=20
aws cloudwatch put-metric-alarm ${DRYRUN}\
--alarm-name "${HN}-diskspaceavailable"\
--alarm-description "Alarm when disk space less that 20GB"\
--actions-enabled\
--ok-actions "${ARN_OF_SNS_TOPIC}"\
--alarm-actions "${ARN_OF_SNS_TOPIC}"\
--insufficient-data-actions "${ARN_OF_SNS_TOPIC}"\
--metric-name DiskSpaceAvailable\
--namespace System/Linux\
--statistic Average\
--dimensions Name=InstanceId,Value=${INSTANCE_ID}, Name=Filesystem\
--period 300\
--threshold ${DISKSPACE_AVAILABLE}\
--comparison-operator LessThanThreshold\
--evaluation-periods 1\
--unit Gigabytes
我首先看到的是您缺少文件系统维度的值。应该是这样的:
--dimensions Name=InstanceId,Value=${INSTANCE_ID}, Name=Filesystem,Value=SOMETHING\
您可以在 CloudWatch 指标控制台中查看维度。将指标添加到图表时,您可以将鼠标悬停在“详细信息”列上并查看所有维度。
Filesystem_value=$(df -h / | tail -1 | awk '{print }')
aws cloudwatch put-metric-alarm ${DRYRUN}\
--alarm-name "${HN}-diskspaceavailable"\
--alarm-description "Alarm when disk space less that 20GB"\
--actions-enabled\
--ok-actions "${ARN_OF_SNS_TOPIC}"\
--alarm-actions "${ARN_OF_SNS_TOPIC}"\
--insufficient-data-actions "${ARN_OF_SNS_TOPIC}"\
--metric-name DiskSpaceAvailable\
--namespace System/Linux\
--statistic Average\
--dimensions Name=Filesystem,Value=${Filesystem_value} Name=InstanceId,Value=${INSTANCE_ID} Name=MountPath,Value=/\
--period 300\
--threshold ${DISKSPACE_AVAILABLE}\
--comparison-operator LessThanThreshold\
--evaluation-periods 1
# --unit Gigabytes
echo 'cloudwatch disk space available alarm has been created'
echo