Skip to content

Instantly share code, notes, and snippets.

@burdara
Last active November 15, 2016 17:58
Show Gist options
  • Save burdara/86a6a779e7cdca2324e317de3cf6e5f4 to your computer and use it in GitHub Desktop.
Save burdara/86a6a779e7cdca2324e317de3cf6e5f4 to your computer and use it in GitHub Desktop.
Installs AWS monitor scripts for reporting memory and disk space.
#!/usr/bin/env bash
#TODO(robbie): this should be handled via IAM role (newer instances).
aws_access_key=""
aws_secret_key=""
install_aws_mon() {
apt-get update
apt-get install -y unzip libwww-perl libdatetime-perl
local aws_mon_file="CloudWatchMonitoringScripts-${1:-1.2.1}.zip"
local script="/opt/aws-scripts-mon/mon-put-instance-data.pl"
local awscred_file="/opt/aws-scripts-mon/awscreds.template"
curl -o "/tmp/$aws_mon_file" "http://aws-cloudwatch.s3.amazonaws.com/downloads/$aws_mon_file"
unzip -o "/tmp/$aws_mon_file" -d "/opt" && rm "/tmp/$aws_mon_file"
chmod 0754 "$script"
# update aws credentials
cat <<EOF > "$awscred_file"
AWSAccessKeyId=$aws_access_key
AWSSecretKey=$aws_secret_key
EOF
# execute memory every minute
local options="--aws-credential-file=$awscred_file --from-cron --mem-util --mem-used --mem-avail"
local line="*/1 * * * * $script $options"
(crontab -u root -l; echo "$line" ) | crontab -u root -
# execute disk chef every hour
local options="--aws-credential-file=$awscred_file --from-cron --disk-path=/ --disk-space-util --disk-space-used --disk-space-avail"
local line="* */1 * * * $script $options"
(crontab -u root -l; echo "$line" ) | crontab -u root -
}
install_aws_mon "1.2.1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment