Skip to content

Instantly share code, notes, and snippets.

@ross-humphrey
Created August 6, 2020 15:54
Show Gist options
  • Save ross-humphrey/2917e12e9bc0a220a93e2f36752f51ab to your computer and use it in GitHub Desktop.
Save ross-humphrey/2917e12e9bc0a220a93e2f36752f51ab to your computer and use it in GitHub Desktop.
💻 EC2 Memory Monitoring

Installing Memory Monitoring On EC2

Handy Commands

Find out what OS you are running (where this is not shown in AWS Console or via the AMI) Unix: cat /etc/os-release

Associate Permissions with EC2

Policy Created: EC2_Memory_Profiling_Policy Role created: EC2_Memory_Profiling_Role

Attach role: Instances, select instance -> Actions -> Instance Settings -> Attach /Replace IAM Role, Add Role above

Ubuntu - packages required (installed)

sudo apt-get update sudo apt-get install unzip sudo apt-get install libwww-perl libdatetime-perl Install Scripts Mkdir monitoring_scripts

Cd monitoring_scripts

curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -O

unzip CloudWatchMonitoringScripts-1.2.2.zip &&
rm CloudWatchMonitoringScripts-1.2.2.zip &&
cd aws-scripts-mon

The package for the monitoring scripts contains the following files: • CloudWatchClient.pm – Shared Perl module that simplifies calling Amazon CloudWatch from other scripts.
 • mon-put-instance-data.pl – Collects system metrics on an Amazon EC2 instance (memory, swap, disk space utilization) and sends them to Amazon CloudWatch.
 • mon-get-instance-stats.pl – Queries Amazon CloudWatch and displays the most recent utilization statistics for the EC2 instance on which this script is executed.
 • awscreds.template – File template for AWS credentials that stores your access key ID and secret access key.
 • LICENSE.txt – Text file containing the Apache 2.0 license.
 • NOTICE.txt – Copyright notice.

Test It all works: (in directory)

./mon-put-instance-data.pl --mem-util --verify --verbose

•	Add to Crontab - runs every 5 minutes
•	vi crontab -e 
•	*/5 * * * * ~/monitoring_scripts/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron
•	

After 5 minutes you should see memory monitoring appear in cloud watch

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