Last active
November 8, 2018 10:36
-
-
Save adrianpietka/525025c863ebb45ca50b44487947c0fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| USERNAME=$1 | |
| AWS_ACCESS_KEY_ID=$2 | |
| AWS_SECRET_KEY=$3 | |
| if [[ -z ${USERNAME} ]] && [[ -z ${AWS_ACCESS_KEY_ID} ]] && [[ -z ${AWS_SECRET_KEY} ]]; then | |
| echo " | |
| Usage: $(basename "$0") [USER NAME] [AWS ACCESS KEY ID] [AWS SECRET KEY]" | |
| exit 1 | |
| fi | |
| DESTINATION_PATH="/home/${USERNAME}/" | |
| AWS_MONITORING=${DESTINATION_PATH}"aws-scripts-mon/" | |
| AWS_CREDENTIALS=${AWS_MONITORING}"awscreds.conf" | |
| apt-get -qq install \ | |
| libdatetime-perl \ | |
| libwww-perl | |
| cd ${DESTINATION_PATH} && \ | |
| curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -s -O && \ | |
| unzip -o CloudWatchMonitoringScripts-1.2.2.zip && \ | |
| rm CloudWatchMonitoringScripts-1.2.2.zip | |
| echo "AWSAccessKeyId=${AWS_ACCESS_KEY_ID} | |
| AWSSecretKey=${AWS_SECRET_KEY}" > $AWS_CREDENTIALS | |
| ${AWS_MONITORING}"mon-put-instance-data.pl" \ | |
| --disk-path=/ \ | |
| --disk-space-util \ | |
| --mem-util \ | |
| --swap-util \ | |
| --aws-credential-file=${AWS_CREDENTIALS} \ | |
| --verify \ | |
| --verbose | |
| if [ $? -ne 0 ]; then | |
| echo "Fail AWS CloudWatch verification" | |
| exit 1 | |
| fi | |
| echo "*/5 * * * * ${USERNAME} ${AWS_MONITORING}mon-put-instance-data.pl --disk-path=/ --disk-space-util --mem-util --swap-util --aws-credential-file=${AWS_CREDENTIALS} --from-cron" >> /etc/crontab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment