Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save martinzuern/02174b5dd69fa75d4b246d046f75b1fd to your computer and use it in GitHub Desktop.
Save martinzuern/02174b5dd69fa75d4b246d046f75b1fd to your computer and use it in GitHub Desktop.
With this user data script, you can set up cron job to put some custom metrics for CloudWatch at instance initiation.
#!/bin/sh
yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA unzip
cd /home/ec2-user
curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O
unzip CloudWatchMonitoringScripts-1.2.1.zip
rm -rf CloudWatchMonitoringScripts-1.2.1.zip
chown ec2-user:ec2-user aws-scripts-mon
echo "* * * * * ec2-user /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-util --swap-util --aggregated --auto-scaling --from-cron" >> /var/spool/cron/ec2-user
echo "0 * * * * ec2-user /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --disk-space-used --disk-space-avail --disk-space-util --disk-path=/ --aggregated --auto-scaling --from-cron" >> /var/spool/cron/ec2-user
@esteban1983cl
Copy link

Very useful thank you !!

@MinhHungTrinh
Copy link

thank you!

@mhtngo
Copy link

mhtngo commented May 29, 2021

Good work! One recommendation: install unzip since we can't assume it's installed on the host:

yum install -y unzip

add before line 5

@martinzuern
Copy link
Author

@mhtngo unzip is installed in line 2 (it’s the very last package)

@kda33
Copy link

kda33 commented Feb 2, 2022

Este es Excelente, Gracias!
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment