Skip to content

Instantly share code, notes, and snippets.

@tankhuu
Last active November 22, 2017 12:12
Show Gist options
  • Save tankhuu/328c293171d0b157c19a365c92d88f14 to your computer and use it in GitHub Desktop.
Save tankhuu/328c293171d0b157c19a365c92d88f14 to your computer and use it in GitHub Desktop.
AWS Utilities - Ubuntu 16.04
#!/usr/bin/env bash
cat << EOF > ~/setup-aws-scripts-mon.sh
#!/usr/bin/env bash
# VARIABLES #
AWSAccessKeyId=\$1
AWSSecretKey=\$2
CRON_DIR=/var/spool/cron/crontabs
# EXECUTE #
# Install libs
sudo apt-get -y update
sudo apt-get install -y unzip libwww-perl libdatetime-perl
# Setup AWS mon scripts
mkdir ~/aws
cd ~/aws
curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O
unzip CloudWatchMonitoringScripts-1.2.1.zip
rm CloudWatchMonitoringScripts-1.2.1.zip
cd aws-scripts-mon
echo "AWSAccessKeyId=\$AWSAccessKeyId" >> awscreds.conf
echo "AWSSecretKey=\$AWSSecretKey" >> awscreds.conf
# Setup cron to collect and send data to AWS every 1 minute
sudo touch \$CRON_DIR/$USER
sudo chmod 600 \$CRON_DIR/$USER
sudo chown $USER:crontab \$CRON_DIR/$USER
echo "*/5 * * * * /home/ubuntu/aws/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --swap-util --from-cron" | sudo tee -a \$CRON_DIR/$USER
EOF
chmod +x /home/ubuntu/setup-aws-scripts-mon.sh
# Execution
/home/ubuntu/setup-aws-scripts-mon.sh AWS_ACCESS_KEY AWS_SECRET_KEY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment