From 384908542a09d9bd59c3c47f6824f2be52fc4e56 Mon Sep 17 00:00:00 2001 From: Yuanruo Liang Date: Wed, 11 Nov 2020 16:56:37 +0800 Subject: [PATCH 1/2] feat(monitoring): add memory monitoring to EC2 instances --- .ebextensions/eb-memory-monitor.config | 43 ++++++++++++++------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/.ebextensions/eb-memory-monitor.config b/.ebextensions/eb-memory-monitor.config index 42a5b62bf5..1687ada298 100644 --- a/.ebextensions/eb-memory-monitor.config +++ b/.ebextensions/eb-memory-monitor.config @@ -1,24 +1,29 @@ ################################################################################################### #### Memory monitoring for Elastic Beanstalk -#### https://medium.com/tomincode/cloudwatch-memory-monitoring-for-elastic-beanstalk-1caa98d57d5c +#### https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-memory-monitoring/ ################################################################################################### +packages: + yum: + perl-DateTime: [] + perl-Sys-Syslog: [] + perl-LWP-Protocol-https: [] + perl-Switch: [] + perl-URI: [] + perl-Bundle-LWP: [] +sources: + /opt/cloudwatch: https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip + container_commands: - 00download: - command: "wget http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip" - ignoreErrors: true - 01extract: - command: "unzip -o CloudWatchMonitoringScripts-1.2.2.zip" - ignoreErrors: true - 02rmzip: - command: "rm CloudWatchMonitoringScripts-1.2.2.zip" - ignoreErrors: true - 03prereq: - command: "yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https" - ignoreErrors: false - 04cdinto: - command: "mv aws-scripts-mon/ /home/ec2-user" - ignoreErrors: true - 05cron: - command: "crontab -l | grep -q 'mon-put-instance-data.pl' || crontab -l | { cat; echo '* * * * * /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail'; } | crontab -" - ignoreErrors: false + 01-setupcron: + command: | + echo '*/5 * * * * root perl /opt/cloudwatch/aws-scripts-mon/mon-put-instance-data.pl `{"Fn::GetOptionSetting" : { "OptionName" : "CloudWatchMetrics", "DefaultValue" : "--mem-util --disk-space-util --disk-path=/" }}` >> /var/log/cwpump.log 2>&1' > /etc/cron.d/cwpump + 02-changeperm: + command: chmod 644 /etc/cron.d/cwpump + 03-changeperm: + command: chmod u+x /opt/cloudwatch/aws-scripts-mon/mon-put-instance-data.pl +option_settings: + "aws:autoscaling:launchconfiguration" : + IamInstanceProfile : "aws-elasticbeanstalk-ec2-role" + "aws:elasticbeanstalk:customoption" : + CloudWatchMetrics : "--mem-util --mem-used --mem-avail --disk-space-util --disk-space-used --disk-space-avail --disk-path=/ --auto-scaling" From aceb6b2e7f3ae14ba28adc1400cf08eae09291fb Mon Sep 17 00:00:00 2001 From: Yuanruo Liang Date: Mon, 16 Nov 2020 10:39:09 +0800 Subject: [PATCH 2/2] doc: Add TODO for change to Amazon Linux 2 instances --- .ebextensions/eb-memory-monitor.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ebextensions/eb-memory-monitor.config b/.ebextensions/eb-memory-monitor.config index 1687ada298..96014c2002 100644 --- a/.ebextensions/eb-memory-monitor.config +++ b/.ebextensions/eb-memory-monitor.config @@ -10,7 +10,7 @@ packages: perl-LWP-Protocol-https: [] perl-Switch: [] perl-URI: [] - perl-Bundle-LWP: [] + perl-Bundle-LWP: [] # TODO(#638): Replace this yum package with perl-Digest-SHA.x86_64 for Amazon Linux 2 instances sources: /opt/cloudwatch: https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip