Skip to content

Instantly share code, notes, and snippets.

@tankhuu
Last active November 13, 2018 09:01
Show Gist options
  • Save tankhuu/4c4b0e9a2217e1f74e9d5d4dcc3eaae1 to your computer and use it in GitHub Desktop.
Save tankhuu/4c4b0e9a2217e1f74e9d5d4dcc3eaae1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# VARIABLES #
AWSAccessKeyId=\$1
AWSSecretKey=\$2
CRON_DIR=/var/spool/cron
# EXECUTE #
# Install libs
sudo yum install -y unzip perl-libwww-perl perl-libdatetime-perl perl-Sys-Syslog perl-DateTime-TimeZone perl-LWP-Protocol-https perl-Crypt-SSLeay
# 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/ec2-user/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
# For AWS AutoScaling Group
# When start new instance, the cache of script for instance-id will make the put metric data script add wrong dimension of instance-id
#UserData:
# !Base64
# Fn::Sub: |
# #cloud-config
# runcmd:
# - sudo -u ec2-user rm /var/tmp/aws-mon/instance-id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment